joplin/CliClient/app/command-use.js

34 lines
798 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 { autocompleteFolders } from './autocomplete.js';
class Command extends BaseCommand {
usage() {
return 'use <notebook>';
}
description() {
return 'Switches to [notebook] - all further operations will happen within this notebook.';
}
aliases() {
return ['cd'];
}
autocomplete() {
return { data: autocompleteFolders };
}
async action(args) {
2017-07-11 18:17:23 +00:00
let folder = await app().loadItem(BaseModel.TYPE_FOLDER, args['notebook']);
2017-07-15 15:35:40 +00:00
if (!folder) throw new Error(_('No folder "%s"', args['notebook']));
2017-07-10 20:03:46 +00:00
app().switchCurrentFolder(folder);
}
}
module.exports = Command;