@@ -36,13 +36,31 @@ if (shouldRejectNodeVersion(process.versions.node)) {
3636const program = new Command ( ) ;
3737
3838/**
39- * Default for the global `--output` flag: the `output` key of the profile's
40- * section in `~/.testsprite/config` when present. Flag values and the
41- * env-selected profile still win; an invalid or absent value falls back to
39+ * Profile used for CONFIG-FILE DEFAULTS. The `--output` default must be
40+ * computed before Commander parses argv, so honor the same precedence the
41+ * real resolution uses (`--profile` flag > TESTSPRITE_PROFILE > "default")
42+ * by peeking argv for the flag. Both `--profile <name>` and `--profile=<name>`
43+ * spellings are recognized; anything unparseable falls back down the chain.
44+ */
45+ function profileForDefaults ( ) : string {
46+ const argv = process . argv ;
47+ const flagIndex = argv . indexOf ( '--profile' ) ;
48+ const next = flagIndex !== - 1 ? argv [ flagIndex + 1 ] : undefined ;
49+ if ( typeof next === 'string' && next . length > 0 && ! next . startsWith ( '-' ) ) return next ;
50+ const inline = argv . find ( arg => arg . startsWith ( '--profile=' ) ) ;
51+ const inlineValue = inline ?. slice ( '--profile=' . length ) ;
52+ if ( typeof inlineValue === 'string' && inlineValue . length > 0 ) return inlineValue ;
53+ return process . env . TESTSPRITE_PROFILE ?? 'default' ;
54+ }
55+
56+ /**
57+ * Default for the global `--output` flag: the `output` key of the selected
58+ * profile's section in `~/.testsprite/config` when present. An explicit
59+ * `--output` flag still wins; an invalid or absent value falls back to
4260 * 'text' (the historical default).
4361 */
4462function configFileOutputDefault ( ) : string {
45- const settings = readConfigFileSettings ( process . env . TESTSPRITE_PROFILE ?? 'default' ) ;
63+ const settings = readConfigFileSettings ( profileForDefaults ( ) ) ;
4664 return isOutputMode ( settings . output ) ? settings . output : 'text' ;
4765}
4866
0 commit comments