1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-02-07 19:30:04 +02:00
joplin/CliClient/app/command-set.js

48 lines
1.1 KiB
JavaScript
Raw Normal View History

const { BaseCommand } = require('./base-command.js');
const { app } = require('./app.js');
const { _ } = require('lib/locale.js');
const { BaseModel } = require('lib/base-model.js');
const { Folder } = require('lib/models/folder.js');
const { Note } = require('lib/models/note.js');
const { BaseItem } = require('lib/models/base-item.js');
2017-07-10 20:03:46 +00:00
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
}
enabled() {
return false;
}
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 18:02:43 +02: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;