fix(cli): honor no-color before rendering help and version (#4248)

Co-authored-by: shuaiyafei <16618929+shuaiyafei@users.noreply.github.com>
This commit is contained in:
他们都不玩了andshuaiyafei authored and GitHub committed 2026-10-17 16:35:41 +01:00
1 parent 4487dd0c9b
commit 64d00f4ab2
2 files changed
+18 -7

No files matched your search

+14 -3
View File
@@ -384,9 +384,20 @@ describe('CLI', () => {
});
it('should disable color with --no-color', async () => {
await cli.run(['--no-color', '--help']);
// Color should be disabled - check output formatter state
expect(cli['output']['colorEnabled']).toBe(false);
const originalColorEnabled = cli['output']['colorEnabled'];
try {
for (const flag of ['--help', '--version', '-V']) {
// CI starts without a TTY; explicitly enable colors so this cannot
// pass merely because the formatter already has colors disabled.
cli['output'].setColorEnabled(true);
consoleOutput.length = 0;
await cli.run(['--no-color', flag]);
expect(cli['output']['colorEnabled']).toBe(false);
expect(consoleOutput.join('')).not.toMatch(/\u001b\[/);
}
} finally {
cli['output'].setColorEnabled(originalColorEnabled);
}
});
});
+4 -4
View File
@@ -108,15 +108,15 @@ export class CLI {
const { command: commandPath, flags, positional } = parseResult;
// Handle global flags
if (flags.noColor || flags.color === false) {
this.output.setColorEnabled(false);
}
if (flags.version || flags.V) {
this.showVersion();
return;
}
if (flags.noColor) {
this.output.setColorEnabled(false);
}
// Set verbosity level based on flags
if (flags.quiet) {
this.output.setVerbosity('quiet');