joplin/CliClient/app/command-set.js

44 lines
1.0 KiB
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';
import { BaseItem } from 'lib/models/base-item.js';
class Command extends BaseCommand {
usage() {
2017-07-28 18:13:07 +00:00
return 'set <note> <name> [value]';
2017-07-10 20:03:46 +00:00
}
description() {
2017-07-18 18:21:03 +00:00
return _('Sets the property <name> of the given <note> to the given [value].');
2017-07-10 20:03:46 +00:00
}
2017-08-04 16:02:43 +00:00
hidden() {
return true;
}
2017-07-10 20:03:46 +00:00
async action(args) {
2017-07-11 18:17:23 +00:00
let title = args['note'];
2017-07-10 20:03:46 +00:00
let propName = args['name'];
let propValue = args['value'];
if (!propValue) propValue = '';
2017-07-11 18:17:23 +00:00
let notes = await app().loadItems(BaseModel.TYPE_NOTE, title);
2017-07-18 18:21:03 +00:00
if (!notes.length) throw new Error(_('Cannot find "%s".', title));
2017-07-10 20:03:46 +00:00
2017-07-11 18:17:23 +00:00
for (let i = 0; i < notes.length; i++) {
let newNote = {
id: notes[i].id,
type_: notes[i].type_,
};
newNote[propName] = propValue;
await Note.save(newNote);
2017-07-10 20:03:46 +00:00
}
}
}
module.exports = Command;