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