diff --git a/README.rst b/README.rst index 3de0e2c..857e638 100644 --- a/README.rst +++ b/README.rst @@ -34,7 +34,7 @@ Support Commands: - group: group name of the record. - item: item name of the record. - value: value of the record. well, there is the place store the password. - - note(optional): note of the record, the lengths of the note is unlimit. + - note(optional): note of the record, the lengths of the note is unlimit but should be within the quotation marks (' or "). Add a record to the program. @@ -43,6 +43,7 @@ Support Commands: args: - record_id: the id of the record, `ls` is a useful command for lookup the record id. + - note(optional): note of the record, the lengths of the note is unlimit but should be within the quotation marks (' or "). Update a record to the program. @@ -74,7 +75,7 @@ some instance:: ====================== help - (papyrus) >>> add web yahoo apassword + (papyrus) >>> add web yahoo apassword 'there is a note.' (papyrus) >>> ls groups * List all (group_id, group) pairs: (0, web) @@ -96,7 +97,7 @@ some instance:: group: web record: yahoo value: apassword - note: None + note: there is a note. created: 2012-10-19_22:24:31.656777 update: 2012-10-19_22:24:31.656777 (papyrus) >>> diff --git a/papyrus.py b/papyrus.py index d5278f9..3dc55e1 100644 --- a/papyrus.py +++ b/papyrus.py @@ -278,11 +278,15 @@ def _validate_line(self, line, lengths, cmd): u"`help {2}` get help message!").format(cmd, line, cmd) if not line: raise PapyrusException(err_msg) - argv = line.strip().split() - if len(argv) not in lengths: + if ("'" in line or '"' in line) and len(line.split()) >= 4: + args = line.split(' ', 3) + args[3] = args[3].strip("'\"") + else: + args = line.strip().split() + if len(args) not in lengths: raise PapyrusException(err_msg) - return argv + return args def _ls_case_groups(self, target): print u"* List all (group_id, group) pairs:" @@ -326,8 +330,8 @@ def do_ls(self, line): List all the groups or records existing in the current program. """ - argv = self._validate_line(line, lengths=(1, 2), cmd='ls') - target = argv[0] + args = self._validate_line(line, lengths=(1, 2), cmd='ls') + target = args[0] if target.isdigit(): target = int(target) @@ -358,9 +362,9 @@ def do_info(self, line): Show the full infomation about specific record. """ - argv = self._validate_line(line, lengths=(1,), cmd='info') + args = self._validate_line(line, lengths=(1,), cmd='info') try: - rid = int(argv[0]) + rid = int(args[0]) record = self.handler.records['_rid'][rid] except ValueError: print "The `record_id` should be a integer." @@ -386,12 +390,13 @@ def do_add(self, line): - group: group name of the record. - item: item name of the record. - value: value of the record. well, there is the place store the password. - - note(optional): note of the record, the lengths of the note is unlimit. + - note(optional): note of the record, the lengths of the note is unlimit + but should be within the quotation marks (' or "). Add a record to the program. """ - argv = self._validate_line(line, lengths=(3, 4), cmd='add') - if not self.handler.add_record(*argv): + args = self._validate_line(line, lengths=(3, 4), cmd='add') + if not self.handler.add_record(*args): raise PapyrusException(u"Fail to add record to the program.") def do_update(self, line): @@ -401,11 +406,13 @@ def do_update(self, line): args:: - record_id: the id of the record, `ls` is a useful command for lookup the record id. + - note(optional): note of the record, the lengths of the note is unlimit + but should be within the quotation marks (' or "). Update a record to the program. """ - argv = self._validate_line(line, lengths=(2, 3), cmd='update') - if not self.handler.update_record(*argv): + args = self._validate_line(line, lengths=(2, 3), cmd='update') + if not self.handler.update_record(*args): raise PapyrusException(u"Fail to update record to the program.") def do_delete(self, line): @@ -418,8 +425,8 @@ def do_delete(self, line): Delete a record to the program. """ - argv = self._validate_line(line, lengths=(1,), cmd='delete') - if not self.handler.delete_record(*argv): + args = self._validate_line(line, lengths=(1,), cmd='delete') + if not self.handler.delete_record(*args): raise PapyrusException(u"Fail to delete record to the program.") # def complete_update(self, text, line, begidx, endidx):