commit 239a23d9633ae13f192d396c4e20f58e84c022c4
parent 3d90bf24eba96d2e326c9fe5027ab20f8704b4cc
Author: Alexey Shiklomanov <ashiklom@bu.edu>
Date: Mon, 2 Oct 2017 16:51:44 -0400
Tag API: Add `tag set` functionality
Use `sncli -k <key> tag set "..."` to set the complete tag string. For
example...
```
sncli -k <key> tag set "tag1,tag2"
```
Diffstat:
1 file changed, 22 insertions(+), 6 deletions(-)
diff --git a/simplenote_cli/sncli.py b/simplenote_cli/sncli.py
@@ -1201,9 +1201,17 @@ def cli_note_tags_get(self, key):
return
tags = utils.get_note_tags(note)
- if tags:
- print(tags)
+ return tags
+
+ def cli_note_tags_set(self, key, tags):
+ note = self.ndb.get_note(key)
+ if not note:
+ self.log('Error: Key does not exist')
+ return
+
+ self.ndb.set_note_tags(key, tags)
+ self.sync_notes()
def SIGINT_handler(signum, frame):
print('\nSignal caught, bye!')
@@ -1239,6 +1247,8 @@ def usage():
< trash | untrash > - trash/untrash a note (specified by <key>)
< pin | unpin > - pin/unpin a note (specified by <key>)
< 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>)
''')
sys.exit(0)
@@ -1367,14 +1377,20 @@ def sncli_start(sync=sync, verbose=verbose, config=config):
# Tag API
elif args[0] == 'tag':
- if args[1] == 'get':
+ if not key:
+ usage()
- if not key:
- usage()
+ if args[1] == 'get':
sn = sncli_start()
- sn.cli_note_tags_get(key)
+ tags = sn.cli_note_tags_get(key)
+ print(tags)
+
+ elif args[1] == 'set':
+ tags = args[2]
+ sn = sncli_start()
+ sn.cli_note_tags_set(key, tags)
else:
usage()