1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-24 08:12:24 +02:00

More CLI changes

This commit is contained in:
Laurent Cozic 2017-06-25 11:41:03 +01:00
parent cf494cfd17
commit 96e77cbb56
3 changed files with 32 additions and 22 deletions

View File

@ -123,7 +123,10 @@ async function main() {
// return;
function switchCurrentFolder(folder) {
if (!folder) throw new Error(_('No active folder is defined.'));
currentFolder = folder;
Setting.setValue('activeFolderId', folder.id);
updatePrompt();
}
@ -192,21 +195,6 @@ async function main() {
}
});
commands.push({
usage: 'use <notebook-title>',
aliases: ['cd'],
description: 'Switches to [notebook-title] - all further operations will happen within this notebook.',
action: async function(args, end) {
let folderTitle = args['notebook-title'];
let folder = await Folder.loadByField('title', folderTitle);
if (!folder) return commandError(this, _('Invalid folder title: %s', folderTitle), end);
switchCurrentFolder(folder);
end();
},
autocomplete: autocompleteFolders,
});
commands.push({
usage: 'mkbook <notebook-title>',
aliases: ['mkdir'],
@ -244,6 +232,21 @@ async function main() {
},
});
commands.push({
usage: 'use <notebook-title>',
aliases: ['cd'],
description: 'Switches to [notebook-title] - all further operations will happen within this notebook.',
action: async function(args, end) {
let folderTitle = args['notebook-title'];
let folder = await Folder.loadByField('title', folderTitle);
if (!folder) return commandError(this, _('Invalid folder title: %s', folderTitle), end);
switchCurrentFolder(folder);
end();
},
autocomplete: autocompleteFolders,
});
commands.push({
usage: 'set <item-title> <prop-name> [prop-value]',
description: 'Sets the given <prop-name> of the given item.',
@ -422,7 +425,7 @@ async function main() {
commands.push({
usage: 'import-enex',
description: _('Imports a .enex file (Evernote export file).'),
description: _('Imports a .enex file (Evernote notebook file).'),
action: function(args, end) {
end();
@ -478,8 +481,11 @@ async function main() {
vorpal.history('net.cozic.joplin'); // Enables persistent history
let defaultFolder = await Folder.defaultFolder();
if (defaultFolder) await execCommand('cd', { 'notebook-title': defaultFolder.title }); // Use execCommand() so that no history entry is created
let activeFolderId = Setting.value('activeFolderId');
let activeFolder = null;
if (activeFolderId) activeFolder = await Folder.load(activeFolderId);
if (!activeFolder) activeFolder = await Folder.defaultFolder();
if (activeFolder) await execCommand('cd', { 'notebook-title': activeFolder.title }); // Use execCommand() so that no history entry is created
vorpal.delimiter(promptString()).show();

View File

@ -21,6 +21,10 @@ class BaseModel {
}
}
static logger() {
return this.db().logger();
}
static tableName() {
throw new Error('Must be overriden');
}

View File

@ -1,5 +1,4 @@
import { BaseModel } from 'lib/base-model.js';
import { Log } from 'lib/log.js';
import { Database } from 'lib/database.js';
class Setting extends BaseModel {
@ -98,7 +97,7 @@ class Setting extends BaseModel {
static saveAll() {
if (!this.updateTimeoutId_) return Promise.resolve();
Log.info('Saving settings...');
this.logger().info('Saving settings...');
clearTimeout(this.updateTimeoutId_);
this.updateTimeoutId_ = null;
@ -109,9 +108,9 @@ class Setting extends BaseModel {
}
return BaseModel.db().transactionExecBatch(queries).then(() => {
Log.info('Settings have been saved.');
this.logger().info('Settings have been saved.');
}).catch((error) => {
Log.warn('Could not save settings', error);
this.logger().warn('Could not save settings', error);
reject(error);
});
}
@ -134,6 +133,7 @@ class Setting extends BaseModel {
Setting.defaults_ = {
'clientId': { value: '', type: 'string' },
'sessionId': { value: '', type: 'string' },
'activeFolderId': { value: '', type: 'string' },
'user.email': { value: '', type: 'string' },
'user.session': { value: '', type: 'string' },
'sync.lastRevId': { value: 0, type: 'int' }, // DEPRECATED