Skip to content

Commit 4c96c72

Browse files
committed
fix(config): honor --profile when computing the config-file --output default
1 parent 0e11244 commit 4c96c72

1 file changed

Lines changed: 22 additions & 4 deletions

File tree

src/index.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,31 @@ if (shouldRejectNodeVersion(process.versions.node)) {
3636
const 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
*/
4462
function 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

Comments
 (0)