nncli

NextCloud Notes Command Line Interface
git clone git://git.danielmoch.com/nncli.git
Log | Files | Refs | LICENSE

commit 4d41e0cf5da752ba2dd784e47b996c959f0d30d3
parent 239a23d9633ae13f192d396c4e20f58e84c022c4
Author: Alexey Shiklomanov <ashiklom@bu.edu>
Date:   Mon,  2 Oct 2017 17:24:45 -0400

Tag API: Implement `tag add`

Same syntax as `tag set`. As a bonus, only adds tags that are not
already present; i.e. running a `tag set "mytag"` multiple times will
only add one instance of `"mytag"`.

Diffstat:
Msimplenote_cli/sncli.py | 29+++++++++++++++++++++++++++++
1 file changed, 29 insertions(+), 0 deletions(-)

diff --git a/simplenote_cli/sncli.py b/simplenote_cli/sncli.py @@ -1213,6 +1213,28 @@ def cli_note_tags_set(self, key, tags): self.ndb.set_note_tags(key, tags) self.sync_notes() + def cli_note_tags_add(self, key, new_tags): + + note = self.ndb.get_note(key) + if not note: + self.log('Error: Key does not exist') + return + + # Add tag only if it isn't already there + old_tags = self.cli_note_tags_get(key) + if old_tags: + old_tag_list = old_tags.split(',') + new_tag_list = new_tags.split(',') + tag_list = old_tag_list + for tag in new_tag_list: + if tag not in tag_list: + tag_list.append(tag) + tags = ','.join(tag_list) + else: + tags = new_tags + + self.cli_note_tags_set(key, tags) + def SIGINT_handler(signum, frame): print('\nSignal caught, bye!') sys.exit(1) @@ -1249,6 +1271,7 @@ def usage(): < markdown | unmarkdown > - markdown/unmarkdown a note (specified by <key>) tag get - retrieve the tags from a note (specified by <key>) tag set <tags> - set the tags for a note (specified by <key>) + tag add <tags> - add tags to a note (specified by <key>) ''') sys.exit(0) @@ -1392,6 +1415,12 @@ def sncli_start(sync=sync, verbose=verbose, config=config): sn = sncli_start() sn.cli_note_tags_set(key, tags) + elif args[1] == 'add': + + new_tags = args[2] + sn = sncli_start() + sn.cli_note_tags_add(key, new_tags) + else: usage()