From 6b23039d951d6a4c9ab980cac4c77b4bfd67b61d Mon Sep 17 00:00:00 2001 From: Laurent Cozic Date: Sun, 25 Jun 2017 15:40:42 +0100 Subject: [PATCH] Added mv --- CliClient/app/main.js | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/CliClient/app/main.js b/CliClient/app/main.js index 8f40a63e19..3c53c95a6e 100644 --- a/CliClient/app/main.js +++ b/CliClient/app/main.js @@ -222,11 +222,11 @@ async function main() { }); commands.push({ - usage: 'mkbook ', + usage: 'mkbook ', aliases: ['mkdir'], description: 'Creates a new notebook', action: function(args, end) { - Folder.save({ title: args['notebook-title'] }).catch((error) => { + Folder.save({ title: args['notebook'] }).catch((error) => { this.log(error); }).then((folder) => { switchCurrentFolder(folder); @@ -259,11 +259,11 @@ async function main() { }); commands.push({ - usage: 'use ', + usage: 'use ', aliases: ['cd'], - description: 'Switches to [notebook-title] - all further operations will happen within this notebook.', + description: 'Switches to [notebook] - all further operations will happen within this notebook.', action: async function(args, end) { - let folderTitle = args['notebook-title']; + let folderTitle = args['notebook']; let folder = await Folder.loadByField('title', folderTitle); if (!folder) return cmdError(this, _('Invalid folder title: %s', folderTitle), end); @@ -348,7 +348,7 @@ async function main() { commands.push({ usage: 'rm ', - description: 'Deletes the given item. For a notebook, all the notes within that notebook will be deleted. Use `rm ../` to delete a notebook.', + description: 'Deletes the given item. For a notebook, all the notes within that notebook will be deleted. Use `rm ../` to delete a notebook.', action: async function(args, end) { let pattern = args['pattern']; let itemType = null; @@ -385,9 +385,29 @@ async function main() { autocomplete: autocompleteItems, }); + commands.push({ + usage: 'mv ', + description: 'Moves the notes matching to .', + action: async function(args, end) { + let pattern = args['pattern']; + + let folder = await Folder.loadByField('title', args['notebook']); + if (!folder) return cmdError(this, _('No folder with title "%s"', args['notebook']), end); + let notes = await Note.previews(currentFolder.id, { titlePattern: pattern }); + if (!notes.length) return cmdError(this, _('No note matches this pattern: "%s"', pattern), end); + + for (let i = 0; i < notes.length; i++) { + await Note.save({ id: notes[i].id, parent_id: folder.id }); + } + + end(); + }, + autocomplete: autocompleteItems, + }); + commands.push({ usage: 'ls [pattern]', - description: 'Displays the notes in [notebook-title]. Use `ls ..` to display the list of notebooks.', + description: 'Displays the notes in [notebook]. Use `ls ..` to display the list of notebooks.', options: [ ['-n, --lines ', 'Displays only the first top lines.'], ['-s, --sort ', 'Sorts the item by (eg. title, updated_time, created_time).'], @@ -452,7 +472,7 @@ async function main() { }); commands.push({ - usage: 'import-enex [notebook-title]', + usage: 'import-enex [notebook]', description: _('Imports en Evernote notebook file (.enex file).'), options: [ ['--fuzzy-matching', 'For debugging purposes. Do not use.'], @@ -460,7 +480,7 @@ async function main() { action: async function(args, end) { let filePath = args.file; let folder = null; - let folderTitle = args['notebook-title']; + let folderTitle = args['notebook']; if (folderTitle) { folder = await Folder.loadByField('title', folderTitle); @@ -553,7 +573,7 @@ async function main() { let activeFolder = null; if (activeFolderId) activeFolder = await Folder.load(activeFolderId); if (!activeFolder) activeFolder = await Folder.defaultFolder(); - if (activeFolder) await execCommand('cd', { 'notebook-title': activeFolder.title }); // Use execCommand() so that no history entry is created + if (activeFolder) await execCommand('cd', { 'notebook': activeFolder.title }); // Use execCommand() so that no history entry is created vorpal.delimiter(promptString()).show();