joplin/CliClient/app/command-config.js

42 lines
1001 B
JavaScript
Raw Normal View History

2017-07-10 20:03:46 +00:00
import { BaseCommand } from './base-command.js';
2017-07-18 18:49:47 +00:00
import { _, setLocale } from 'lib/locale.js';
import { app } from './app.js';
2017-07-10 20:03:46 +00:00
import { Setting } from 'lib/models/setting.js';
class Command extends BaseCommand {
usage() {
2017-07-18 18:49:47 +00:00
return 'config [name] [value]';
2017-07-10 20:03:46 +00:00
}
description() {
2017-07-18 18:21:03 +00:00
return _('Gets or sets a config value. If [value] is not provided, it will show the value of [name]. If neither [name] nor [value] is provided, it will list the current configuration.');
2017-07-10 20:03:46 +00:00
}
async action(args) {
if (!args.name && !args.value) {
let keys = Setting.publicKeys();
for (let i = 0; i < keys.length; i++) {
this.log(keys[i] + ' = ' + Setting.value(keys[i]));
}
return;
}
if (args.name && !args.value) {
this.log(args.name + ' = ' + Setting.value(args.name));
return;
}
Setting.setValue(args.name, args.value);
2017-07-18 18:49:47 +00:00
if (args.name == 'locale') {
setLocale(Setting.value('locale'));
app().onLocaleChanged();
}
2017-07-10 20:03:46 +00:00
await Setting.saveAll();
}
}
module.exports = Command;