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

51 lines
1.3 KiB
JavaScript
Raw Normal View History

const { BaseCommand } = require('./base-command.js');
const { app } = require('./app.js');
const { _ } = require('lib/locale.js');
2017-12-14 20:12:14 +02:00
const BaseModel = require('lib/BaseModel.js');
2017-12-07 20:12:46 +02:00
const { Database } = require('lib/database.js');
2017-12-14 20:12:14 +02:00
const Folder = require('lib/models/Folder.js');
const Note = require('lib/models/Note.js');
const BaseItem = require('lib/models/BaseItem.js');
2017-07-10 22:03:46 +02:00
class Command extends BaseCommand {
usage() {
2017-07-28 20:13:07 +02:00
return 'set <note> <name> [value]';
2017-07-10 22:03:46 +02:00
}
description() {
2017-12-07 20:12:46 +02:00
const fields = Note.fields();
const s = [];
for (let i = 0; i < fields.length; i++) {
const f = fields[i];
if (f.name === 'id') continue;
s.push(f.name + ' (' + Database.enumName('fieldType', f.type) + ')');
}
2017-07-10 22:03:46 +02:00
2017-12-07 20:12:46 +02:00
return _('Sets the property <name> of the given <note> to the given [value]. Possible properties are:\n\n%s', s.join(', '));
2017-08-04 18:02:43 +02:00
}
2017-07-10 22:03:46 +02:00
async action(args) {
2017-07-11 20:17:23 +02:00
let title = args['note'];
2017-07-10 22:03:46 +02:00
let propName = args['name'];
let propValue = args['value'];
if (!propValue) propValue = '';
2017-07-11 20:17:23 +02:00
let notes = await app().loadItems(BaseModel.TYPE_NOTE, title);
2017-07-18 20:21:03 +02:00
if (!notes.length) throw new Error(_('Cannot find "%s".', title));
2017-07-10 22:03:46 +02:00
2017-07-11 20:17:23 +02:00
for (let i = 0; i < notes.length; i++) {
2017-12-26 12:38:53 +02:00
this.encryptionCheck(notes[i]);
2017-07-11 20:17:23 +02:00
let newNote = {
id: notes[i].id,
type_: notes[i].type_,
};
newNote[propName] = propValue;
await Note.save(newNote);
2017-07-10 22:03:46 +02:00
}
}
}
module.exports = Command;