joplin/CliClient/app/command-cat.js

41 lines
977 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';
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 { autocompleteItems } from './autocomplete.js';
class Command extends BaseCommand {
usage() {
return 'cat <title>';
}
description() {
return 'Displays the given item data.';
}
options() {
return [
['-v, --verbose', 'Shows complete information about note.'],
];
}
2017-07-10 20:03:46 +00:00
autocomplete() {
return { data: autocompleteItems };
}
async action(args) {
let title = args['title'];
2017-07-15 15:35:40 +00:00
let item = await app().loadItem(BaseModel.TYPE_NOTE, title, { parent: app().currentFolder() });
2017-07-11 18:17:23 +00:00
if (!item) throw new Error(_('No item "%s" found.', title));
2017-07-10 20:03:46 +00:00
const content = args.options.verbose ? await Note.serialize(item) : await Note.serializeForEdit(item);
2017-07-10 20:03:46 +00:00
this.log(content);
}
}
module.exports = Command;