joplin/CliClient/app/command-mv.js

35 lines
950 B
JavaScript
Raw Normal View History

2017-07-10 20:03:46 +00:00
import { BaseCommand } from './base-command.js';
import { app } from './app.js';
import { _ } from 'lib/locale.js';
2017-07-11 18:17:23 +00:00
import { BaseModel } from 'lib/base-model.js';
2017-07-10 20:03:46 +00:00
import { Folder } from 'lib/models/folder.js';
import { Note } from 'lib/models/note.js';
class Command extends BaseCommand {
usage() {
2017-08-04 16:02:43 +00:00
return 'mv <note-pattern> [notebook]';
2017-07-10 20:03:46 +00:00
}
description() {
2017-08-04 16:02:43 +00:00
return _('Moves the notes matching <note-pattern> to [notebook].');
2017-07-10 20:03:46 +00:00
}
async action(args) {
2017-08-04 16:02:43 +00:00
const pattern = args['note-pattern'];
const destination = args['notebook'];
const folder = await Folder.loadByField('title', destination);
if (!folder) throw new Error(_('Cannot find "%s".', destination));
2017-07-10 20:03:46 +00:00
2017-08-04 16:02:43 +00:00
const notes = await app().loadItems(BaseModel.TYPE_NOTE, pattern);
if (!notes.length) throw new Error(_('Cannot find "%s".', pattern));
2017-07-10 20:03:46 +00:00
2017-08-04 16:02:43 +00:00
for (let i = 0; i < notes.length; i++) {
await Note.moveToFolder(notes[i].id, folder.id);
2017-07-10 20:03:46 +00:00
}
}
}
module.exports = Command;