Skip to content

Commit 9377289

Browse files
author
deepshekhardas
committed
fix(cli): respect --profile flag by lazily evaluating default profile name
The CommonCommandOptions schema was evaluating the default profile name at module load time, which caused the --profile option to be ignored. Changed to use an optional string with a .transform() to lazily evaluate the default only when needed. Fixes #2542
1 parent e1f8134 commit 9377289

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

packages/cli-v3/src/cli/common.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@ export const CommonCommandOptions = z.object({
1313
apiUrl: z.string().optional(),
1414
logLevel: z.enum(["debug", "info", "log", "warn", "error", "none"]).default("log"),
1515
skipTelemetry: z.boolean().default(false),
16-
profile: z.string().default(readAuthConfigCurrentProfileName()),
16+
profile: z
17+
.string()
18+
.optional()
19+
.transform((v) => v ?? readAuthConfigCurrentProfileName()),
1720
});
1821

1922
export type CommonCommandOptions = z.infer<typeof CommonCommandOptions>;
2023

2124
export function commonOptions(command: Command) {
2225
return command
23-
.option("--profile <profile>", "The login profile to use", readAuthConfigCurrentProfileName())
26+
.option("--profile <profile>", "The login profile to use")
2427
.option("-a, --api-url <value>", "Override the API URL", CLOUD_API_URL)
2528
.option(
2629
"-l, --log-level <level>",
@@ -30,9 +33,9 @@ export function commonOptions(command: Command) {
3033
.option("--skip-telemetry", "Opt-out of sending telemetry");
3134
}
3235

33-
export class SkipLoggingError extends Error {}
34-
export class SkipCommandError extends Error {}
35-
export class OutroCommandError extends SkipCommandError {}
36+
export class SkipLoggingError extends Error { }
37+
export class SkipCommandError extends Error { }
38+
export class OutroCommandError extends SkipCommandError { }
3639

3740
export async function handleTelemetry(action: () => Promise<void>) {
3841
try {

0 commit comments

Comments
 (0)