From 78ba57f612b372bb316c851f18f56623c053cdbf Mon Sep 17 00:00:00 2001 From: Roy Razon Date: Wed, 14 Feb 2024 10:48:08 +0200 Subject: [PATCH] fix: CLI profile config view without driver - `profile config view`: do not throw error if a driver is not set - use `jsonEnabled` instead of `flags.json` to test for JSON output --- .../cli-common/src/commands/base-command.ts | 2 +- .../cli/src/commands/profile/config/update.ts | 2 +- .../cli/src/commands/profile/config/view.ts | 17 ++++++++++------- packages/cli/src/commands/profile/current.ts | 2 +- packages/cli/src/commands/profile/key.ts | 2 +- packages/cli/src/commands/profile/ls.ts | 2 +- 6 files changed, 15 insertions(+), 12 deletions(-) diff --git a/packages/cli-common/src/commands/base-command.ts b/packages/cli-common/src/commands/base-command.ts index d0ab35e0..b55d4545 100644 --- a/packages/cli-common/src/commands/base-command.ts +++ b/packages/cli-common/src/commands/base-command.ts @@ -119,7 +119,7 @@ abstract class BaseCommand extends Comm oclifSettings.debug = true } this.#rawArgs = raw - this.logger = commandLogger(this, this.flags.json ? 'stderr' : 'stdout') + this.logger = commandLogger(this, this.jsonEnabled() ? 'stderr' : 'stdout') this.stdErrLogger = commandLogger(this, 'stderr') } diff --git a/packages/cli/src/commands/profile/config/update.ts b/packages/cli/src/commands/profile/config/update.ts index b8e5eb98..67c4ce4b 100644 --- a/packages/cli/src/commands/profile/config/update.ts +++ b/packages/cli/src/commands/profile/config/update.ts @@ -66,7 +66,7 @@ export default class UpdateProfileConfig extends ProfileCommand { const pStore = profileStore(this.store).ref - const driver = this.profile.driver as DriverName - const config = await pStore.defaultDriverFlags(driver) + const driver = this.profile.driver as DriverName | undefined if (!driver) { - ux.error([ - 'Missing driver configuration in profile.', - `Run ${text.command(this.config, 'profile config update --driver ')} to set the desired machine driver`, - ].join(EOL)) + if (this.jsonEnabled()) { + return { driver: null, defaultFlags: {} } + } + ux.info('No driver specified in profile.') + ux.info(`Run ${text.command(this.config, 'profile config update --driver ')} to set a driver`) + return undefined } - if (this.flags.json) { + + const config = await pStore.defaultDriverFlags(driver) + if (this.jsonEnabled()) { return { driver, defaultFlags: config } } ux.info(`Current configuration for driver ${text.code(driver)}:`) diff --git a/packages/cli/src/commands/profile/current.ts b/packages/cli/src/commands/profile/current.ts index af95ff18..5020d7c1 100644 --- a/packages/cli/src/commands/profile/current.ts +++ b/packages/cli/src/commands/profile/current.ts @@ -15,6 +15,6 @@ export default class CurrentProfile extends ProfileCommand { throw new Error('Could not find tunneling key in profile store') } const value = await extractKey(tunnelingKey, this.args.type as KeyType) - if (this.flags.json) { + if (this.jsonEnabled()) { return value } ux.log(value) diff --git a/packages/cli/src/commands/profile/ls.ts b/packages/cli/src/commands/profile/ls.ts index 7c878bf3..1aa24d26 100644 --- a/packages/cli/src/commands/profile/ls.ts +++ b/packages/cli/src/commands/profile/ls.ts @@ -18,7 +18,7 @@ export default class ListProfile extends ProfileCommand { async run(): Promise { const { profiles, current } = await this.profileConfig.list() - if (this.flags.json) { + if (this.jsonEnabled()) { return { profiles, current } }