Skip to content

Commit 03e7313

Browse files
committed
fix(cli): respect CP_VERBOSE if --verbose argument not given
1 parent 38ad415 commit 03e7313

File tree

4 files changed

+11
-18
lines changed

4 files changed

+11
-18
lines changed

e2e/cli-e2e/tests/__snapshots__/help.e2e.test.ts.snap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ Commands:
1818
1919
2020
Global Options:
21-
--verbose When true creates more verbose output. This is helpful w
22-
hen debugging. You may also set CP_VERBOSE env variable
23-
instead. [boolean] [default: false]
21+
--verbose Toggles whether to print debug logs. The default value is de
22+
rived from the CP_VERBOSE environment variable (false if not
23+
set). [boolean]
2424
--config Path to config file. By default it loads code-pushup.con
2525
fig.(ts|mjs|js). [string]
2626
--tsconfig Path to a TypeScript config, to be used when loading con

packages/cli/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -195,11 +195,11 @@ Each example is fully tested to demonstrate best practices for plugin testing as
195195

196196
### Global Options
197197

198-
| Option | Type | Default | Description |
199-
| ---------------- | --------- | -------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------- |
200-
| **`--verbose`** | `boolean` | `false` | When true creates more verbose output. This is helpful when debugging. You may also set `CP_VERBOSE` env variable instead. |
201-
| **`--config`** | `string` | looks for `code-pushup.config.{ts\|mjs\|js}` | Path to config file. |
202-
| **`--tsconfig`** | `string` | n/a | Path to a TypeScript config, used to load config file. |
198+
| Option | Type | Default | Description |
199+
| ---------------- | --------- | ----------------------------------------------------- | ------------------------------------------------------ |
200+
| **`--verbose`** | `boolean` | `process.env['CP_VERBOSE']` if set, otherwise `false` | Toggles whether to print debug logs. |
201+
| **`--config`** | `string` | looks for `code-pushup.config.{ts\|mjs\|js}` | Path to config file. |
202+
| **`--tsconfig`** | `string` | n/a | Path to a TypeScript config, used to load config file. |
203203

204204
> [!NOTE]
205205
> By default, the CLI loads `code-pushup.config.(ts|mjs|js)` if no config path is provided with `--config`.

packages/cli/src/lib/implementation/global.options.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ export function yargsGlobalOptionsDefinition(): Record<
88
return {
99
verbose: {
1010
describe:
11-
'When true creates more verbose output. This is helpful when debugging. You may also set CP_VERBOSE env variable instead.',
11+
'Toggles whether to print debug logs. The default value is derived from the CP_VERBOSE environment variable (false if not set).',
1212
type: 'boolean',
13-
default: false,
1413
},
1514
config: {
1615
describe:

packages/cli/src/lib/yargs-cli.int.test.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,6 @@ import { options } from './options.js';
1616
import { yargsCli } from './yargs-cli.js';
1717

1818
describe('yargsCli', () => {
19-
it('should provide correct default values for global options', async () => {
20-
const parsedArgv = await yargsCli<GlobalOptions>([], {
21-
options,
22-
}).parseAsync();
23-
expect(parsedArgv.verbose).toBe(false);
24-
});
25-
2619
it('should parse an empty array as a default onlyPlugins option', async () => {
2720
const parsedArgv = await yargsCli<GlobalOptions & FilterOptions>([], {
2821
options: { ...options, ...yargsFilterOptionsDefinition() },
@@ -144,7 +137,8 @@ describe('yargsCli', () => {
144137
expect(parsedArgv).toEqual(
145138
expect.objectContaining({
146139
// default values
147-
verbose: false,
140+
onlyCategories: [],
141+
skipCategories: [],
148142
// overridden arguments
149143
persist: expect.objectContaining({
150144
outputDir: 'code-pushdown/output/dir',

0 commit comments

Comments
 (0)