@@ -20,13 +20,31 @@ import { VERSION } from './version.js';
2020const program = new Command ( ) ;
2121
2222/**
23- * Default for the global `--output` flag: the `output` key of the profile's
24- * section in `~/.testsprite/config` when present. Flag values and the
25- * env-selected profile still win; an invalid or absent value falls back to
23+ * Profile used for CONFIG-FILE DEFAULTS. The `--output` default must be
24+ * computed before Commander parses argv, so honor the same precedence the
25+ * real resolution uses (`--profile` flag > TESTSPRITE_PROFILE > "default")
26+ * by peeking argv for the flag. Both `--profile <name>` and `--profile=<name>`
27+ * spellings are recognized; anything unparseable falls back down the chain.
28+ */
29+ function profileForDefaults ( ) : string {
30+ const argv = process . argv ;
31+ const flagIndex = argv . indexOf ( '--profile' ) ;
32+ const next = flagIndex !== - 1 ? argv [ flagIndex + 1 ] : undefined ;
33+ if ( typeof next === 'string' && next . length > 0 && ! next . startsWith ( '-' ) ) return next ;
34+ const inline = argv . find ( arg => arg . startsWith ( '--profile=' ) ) ;
35+ const inlineValue = inline ?. slice ( '--profile=' . length ) ;
36+ if ( typeof inlineValue === 'string' && inlineValue . length > 0 ) return inlineValue ;
37+ return process . env . TESTSPRITE_PROFILE ?? 'default' ;
38+ }
39+
40+ /**
41+ * Default for the global `--output` flag: the `output` key of the selected
42+ * profile's section in `~/.testsprite/config` when present. An explicit
43+ * `--output` flag still wins; an invalid or absent value falls back to
2644 * 'text' (the historical default).
2745 */
2846function configFileOutputDefault ( ) : string {
29- const settings = readConfigFileSettings ( process . env . TESTSPRITE_PROFILE ?? 'default' ) ;
47+ const settings = readConfigFileSettings ( profileForDefaults ( ) ) ;
3048 return isOutputMode ( settings . output ) ? settings . output : 'text' ;
3149}
3250
0 commit comments