Skip to content

Commit

Permalink
fix: fall back to scopedEnvVarKey if scopedEnvVarKeys is not defined (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley authored Jul 28, 2023
1 parent ceb804a commit cc63a56
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,10 +224,10 @@ export abstract class Command {

protected async _run<T>(): Promise<T> {
let err: Error | undefined
let result
let result: T | undefined
try {
// remove redirected env var to allow subsessions to run autoupdated client
this.config.scopedEnvVarKeys('REDIRECTED').map(key => delete process.env[key])
this.removeEnvVar('REDIRECTED')
await this.init()
result = await this.run()
} catch (error: any) {
Expand Down Expand Up @@ -391,6 +391,17 @@ export abstract class Command {
protected logJson(json: unknown): void {
ux.styledJSON(json)
}

private removeEnvVar(envVar: string): void {
const keys: string[] = []
try {
keys.push(...this.config.scopedEnvVarKeys(envVar))
} catch {
keys.push(this.config.scopedEnvVarKey(envVar))
}

keys.map(key => delete process.env[key])
}
}

export namespace Command {
Expand Down

0 comments on commit cc63a56

Please sign in to comment.