Cli: Fixed version command so that it does not require the keychain

release-2.2
Laurent Cozic 2021-08-11 16:23:37 +01:00
parent 8108af4e74
commit 15766d18f5
3 changed files with 23 additions and 6 deletions

View File

@ -402,8 +402,16 @@ class Application extends BaseApplication {
} }
} }
// We need this special case here because by the time the `version` command
// runs, the keychain has already been setup.
checkIfKeychainEnabled(argv) {
return argv.indexOf('version') < 0;
}
async start(argv) { async start(argv) {
argv = await super.start(argv); const keychainEnabled = this.checkIfKeychainEnabled(argv);
argv = await super.start(argv, { keychainEnabled });
cliUtils.setStdout(object => { cliUtils.setStdout(object => {
return this.stdout(object); return this.stdout(object);

View File

@ -1,6 +1,6 @@
const { BaseCommand } = require('./base-command.js'); const { BaseCommand } = require('./base-command.js');
const Setting = require('@joplin/lib/models/Setting').default;
const { _ } = require('@joplin/lib/locale'); const { _ } = require('@joplin/lib/locale');
const versionInfo = require('@joplin/lib/versionInfo').default;
class Command extends BaseCommand { class Command extends BaseCommand {
usage() { usage() {
@ -12,8 +12,7 @@ class Command extends BaseCommand {
} }
async action() { async action() {
const p = require('./package.json'); this.stdout(versionInfo(require('./package.json')).message);
this.stdout(_('%s %s (%s)', p.name, p.version, Setting.value('env')));
} }
} }

View File

@ -4,6 +4,7 @@ import shim from './shim';
import BaseService from './services/BaseService'; import BaseService from './services/BaseService';
import reducer, { setStore } from './reducer'; import reducer, { setStore } from './reducer';
import KeychainServiceDriver from './services/keychain/KeychainServiceDriver.node'; import KeychainServiceDriver from './services/keychain/KeychainServiceDriver.node';
import KeychainServiceDriverDummy from './services/keychain/KeychainServiceDriver.dummy';
import { _, setLocale } from './locale'; import { _, setLocale } from './locale';
import KvStore from './services/KvStore'; import KvStore from './services/KvStore';
import SyncTargetJoplinServer from './SyncTargetJoplinServer'; import SyncTargetJoplinServer from './SyncTargetJoplinServer';
@ -55,6 +56,10 @@ const appLogger: LoggerWrapper = Logger.create('App');
// const ntpClient = require('./vendor/ntp-client'); // const ntpClient = require('./vendor/ntp-client');
// ntpClient.dgram = require('dgram'); // ntpClient.dgram = require('dgram');
interface StartOptions {
keychainEnabled?: boolean;
}
export default class BaseApplication { export default class BaseApplication {
private eventEmitter_: any; private eventEmitter_: any;
@ -655,7 +660,12 @@ export default class BaseApplication {
return toSystemSlashes(output, 'linux'); return toSystemSlashes(output, 'linux');
} }
async start(argv: string[]): Promise<any> { async start(argv: string[], options: StartOptions = null): Promise<any> {
options = {
keychainEnabled: true,
...options,
};
const startFlags = await this.handleStartFlags_(argv); const startFlags = await this.handleStartFlags_(argv);
argv = startFlags.argv; argv = startFlags.argv;
@ -744,7 +754,7 @@ export default class BaseApplication {
reg.setDb(this.database_); reg.setDb(this.database_);
BaseModel.setDb(this.database_); BaseModel.setDb(this.database_);
await loadKeychainServiceAndSettings(KeychainServiceDriver); await loadKeychainServiceAndSettings(options.keychainEnabled ? KeychainServiceDriver : KeychainServiceDriverDummy);
await handleSyncStartupOperation(); await handleSyncStartupOperation();
appLogger.info(`Client ID: ${Setting.value('clientId')}`); appLogger.info(`Client ID: ${Setting.value('clientId')}`);