diff --git a/CliClient/app/autocompletion.js b/CliClient/app/autocompletion.js index af82fffc1..63835dee6 100644 --- a/CliClient/app/autocompletion.js +++ b/CliClient/app/autocompletion.js @@ -30,6 +30,11 @@ async function handleAutocompletionPromise(line) { if (metadata === undefined) { return line; } + + if (words[0] === 'tag' && words[1] === 'notetags') { + metadata.usage = 'tag '; + } + // complete an option let next = words.length > 1 ? words[words.length - 1] : ''; let l = []; @@ -100,7 +105,7 @@ async function handleAutocompletionPromise(line) { } if (argName == 'tag-command') { - let c = filterList(['add', 'remove', 'list'], next); + let c = filterList(['add', 'remove', 'list', 'notetags'], next); l.push(...c); } diff --git a/CliClient/app/command-tag.js b/CliClient/app/command-tag.js index eb5d2dbf6..62444ee65 100644 --- a/CliClient/app/command-tag.js +++ b/CliClient/app/command-tag.js @@ -11,7 +11,7 @@ class Command extends BaseCommand { } description() { - return _(' can be "add", "remove" or "list" to assign or remove [tag] from [note], or to list the notes associated with [tag]. The command `tag list` can be used to list all the tags (use -l for long option).'); + return _(' can be "add", "remove", "list", or "notetags" to assign or remove [tag] from [note], to list notes associated with [tag], or to list tags associated with [note]. The command `tag list` can be used to list all the tags (use -l for long option).'); } options() { @@ -75,6 +75,18 @@ class Command extends BaseCommand { this.stdout(tag.title); }); } + } else if (command == 'notetags') { + if (args.tag) { + let note = await app().loadItems(BaseModel.TYPE_NOTE, args.tag); + if (note.length < 1) throw new Error(_('Cannot find note with id "%s".', args.tag)); + if (note.length > 1) throw new Error(_('Multiple notes match the id "%s". Please be more specific', args.tag)); + let tags = await Tag.tagsByNoteId(note[0].id); + tags.map(tag => { + this.stdout(tag.title); + }); + } else { + throw new Error(_('Missing required argument: note')); + } } else { throw new Error(_('Invalid command: "%s"', command)); }