Skip to content

Commit

Permalink
fix: CLI profile config view without driver
Browse files Browse the repository at this point in the history
- `profile config view`: do not throw error if a driver is not set
- use `jsonEnabled` instead of `flags.json` to test for JSON output
  • Loading branch information
Roy Razon committed Feb 14, 2024
1 parent 7c25a96 commit 78ba57f
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 12 deletions.
2 changes: 1 addition & 1 deletion packages/cli-common/src/commands/base-command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ abstract class BaseCommand<T extends typeof Command=typeof Command> 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')
}

Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/profile/config/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ export default class UpdateProfileConfig extends ProfileCommand<typeof UpdatePro
const profileDriver = this.profile.driver as DriverName | undefined
const driver: DriverName | undefined = (this.flags.driver || profileDriver)
if (!driver) {
ux.error('Missing driver configuration in profile, use the --driver flag to set the desired machine driver')
ux.error(`Missing driver configuration in profile, specify the ${text.code('--driver')} flag to set the driver`)
}
const { unset } = this.flags
validateUnset(driver, unset)
Expand Down
17 changes: 10 additions & 7 deletions packages/cli/src/commands/profile/config/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ export default class ViewProfileConfig extends ProfileCommand<typeof ViewProfile

async run(): Promise<unknown> {
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 <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 <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)}:`)
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/profile/current.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export default class CurrentProfile extends ProfileCommand<typeof CurrentProfile
}
const { alias, id, location } = currentProfile
const result = { alias, id, location }
return this.flags.json ? result : ux.styledObject(result)
return this.jsonEnabled() ? result : ux.styledObject(result)
}
}
2 changes: 1 addition & 1 deletion packages/cli/src/commands/profile/key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export default class Key extends ProfileCommand<typeof Key> {
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)
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/commands/profile/ls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default class ListProfile extends ProfileCommand<typeof ListProfile> {
async run(): Promise<unknown> {
const { profiles, current } = await this.profileConfig.list()

if (this.flags.json) {
if (this.jsonEnabled()) {
return { profiles, current }
}

Expand Down

0 comments on commit 78ba57f

Please sign in to comment.