1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

CLI: Resolves #1974: Add command to list all tags for a note (#2003)

* Add command to list tags associated with a given note

* Update description

* Fix autocompletion to do notes instead of tags when tag-command is notetags
This commit is contained in:
Hanna Bennett 2019-10-30 02:43:47 -07:00 committed by Laurent Cozic
parent 885858dcb4
commit 0386534b3a
2 changed files with 19 additions and 2 deletions

View File

@ -30,6 +30,11 @@ async function handleAutocompletionPromise(line) {
if (metadata === undefined) {
return line;
}
if (words[0] === 'tag' && words[1] === 'notetags') {
metadata.usage = 'tag <tag-command> <note>';
}
// 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);
}

View File

@ -11,7 +11,7 @@ class Command extends BaseCommand {
}
description() {
return _('<tag-command> 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 _('<tag-command> 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));
}