Skip to content

Commit dcf5665

Browse files
committed
refactor: use CP_VERBOSE flag instead of verbose param
1 parent a0638f8 commit dcf5665

25 files changed

+173
-166
lines changed

packages/cli/src/lib/implementation/core-config.middleware.integration.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const configDirPath = path.join(
2121
describe('coreConfigMiddleware', () => {
2222
const CLI_DEFAULTS = {
2323
progress: true,
24-
verbose: false,
24+
plugins: [],
2525
onlyPlugins: [],
2626
skipPlugins: [],
2727
};

packages/cli/src/lib/implementation/core-config.model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export type UploadConfigCliOptions = {
1616
export type ConfigCliOptions = {
1717
config?: string;
1818
tsconfig?: string;
19+
verbose?: string;
1920
};
2021

2122
export type CoreConfigCliOptions = Pick<CoreConfig, 'persist'> & {

packages/cli/src/lib/implementation/filter.middleware.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ export function filterMiddleware<T extends FilterOptions>(
3030
onlyCategories = [],
3131
skipPlugins = [],
3232
onlyPlugins = [],
33-
verbose = false,
3433
} = originalProcessArgs;
3534

3635
const plugins = filterSkippedInPlugins(rcPlugins);
@@ -43,7 +42,7 @@ export function filterMiddleware<T extends FilterOptions>(
4342
onlyPlugins.length === 0
4443
) {
4544
if (rcCategories && categories) {
46-
validateSkippedCategories(rcCategories, categories, verbose);
45+
validateSkippedCategories(rcCategories, categories);
4746
}
4847
return {
4948
...originalProcessArgs,
@@ -61,12 +60,12 @@ export function filterMiddleware<T extends FilterOptions>(
6160
const filteredCategories = applyCategoryFilters(
6261
{ categories, plugins },
6362
skippedCategories,
64-
{ skipCategories, onlyCategories, verbose },
63+
{ skipCategories, onlyCategories },
6564
);
6665
const filteredPlugins = applyPluginFilters(
6766
{ categories: filteredCategories, plugins },
6867
skippedPlugins,
69-
{ skipPlugins, onlyPlugins, verbose },
68+
{ skipPlugins, onlyPlugins },
7069
);
7170
const finalCategories = filteredCategories
7271
? filterItemRefsBy(filteredCategories, ref =>
@@ -89,9 +88,9 @@ export function filterMiddleware<T extends FilterOptions>(
8988
function applyCategoryFilters(
9089
{ categories, plugins }: Filterables,
9190
skippedCategories: string[],
92-
options: Pick<FilterOptions, 'skipCategories' | 'onlyCategories' | 'verbose'>,
91+
options: Pick<FilterOptions, 'skipCategories' | 'onlyCategories'>,
9392
): CoreConfig['categories'] {
94-
const { skipCategories = [], onlyCategories = [], verbose = false } = options;
93+
const { skipCategories = [], onlyCategories = [] } = options;
9594
if (
9695
(skipCategories.length === 0 && onlyCategories.length === 0) ||
9796
((!categories || categories.length === 0) && skippedCategories.length === 0)
@@ -101,22 +100,22 @@ function applyCategoryFilters(
101100
validateFilterOption(
102101
'skipCategories',
103102
{ plugins, categories },
104-
{ itemsToFilter: skipCategories, skippedItems: skippedCategories, verbose },
103+
{ itemsToFilter: skipCategories, skippedItems: skippedCategories },
105104
);
106105
validateFilterOption(
107106
'onlyCategories',
108107
{ plugins, categories },
109-
{ itemsToFilter: onlyCategories, skippedItems: skippedCategories, verbose },
108+
{ itemsToFilter: onlyCategories, skippedItems: skippedCategories },
110109
);
111110
return applyFilters(categories ?? [], skipCategories, onlyCategories, 'slug');
112111
}
113112

114113
function applyPluginFilters(
115114
{ categories, plugins }: Filterables,
116115
skippedPlugins: string[],
117-
options: Pick<FilterOptions, 'skipPlugins' | 'onlyPlugins' | 'verbose'>,
116+
options: Pick<FilterOptions, 'skipPlugins' | 'onlyPlugins'>,
118117
): CoreConfig['plugins'] {
119-
const { skipPlugins = [], onlyPlugins = [], verbose = false } = options;
118+
const { skipPlugins = [], onlyPlugins = [] } = options;
120119
const filteredPlugins = filterPluginsFromCategories({
121120
categories,
122121
plugins,
@@ -127,12 +126,12 @@ function applyPluginFilters(
127126
validateFilterOption(
128127
'skipPlugins',
129128
{ plugins: filteredPlugins, categories },
130-
{ itemsToFilter: skipPlugins, skippedItems: skippedPlugins, verbose },
129+
{ itemsToFilter: skipPlugins, skippedItems: skippedPlugins },
131130
);
132131
validateFilterOption(
133132
'onlyPlugins',
134133
{ plugins: filteredPlugins, categories },
135-
{ itemsToFilter: onlyPlugins, skippedItems: skippedPlugins, verbose },
134+
{ itemsToFilter: onlyPlugins, skippedItems: skippedPlugins },
136135
);
137136
return applyFilters(filteredPlugins, skipPlugins, onlyPlugins, 'slug');
138137
}

packages/cli/src/lib/implementation/filter.middleware.unit.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,8 @@ describe('filterMiddleware', () => {
291291
);
292292

293293
it('should trigger verbose logging when skipPlugins or onlyPlugins removes categories', () => {
294+
vi.stubEnv('CP_VERBOSE', 'true');
295+
294296
filterMiddleware({
295297
onlyPlugins: ['p1'],
296298
skipPlugins: ['p2'],
@@ -311,7 +313,6 @@ describe('filterMiddleware', () => {
311313
refs: [{ type: 'audit', plugin: 'p2', slug: 'a1-p2', weight: 1 }],
312314
},
313315
] as CategoryConfig[],
314-
verbose: true,
315316
});
316317

317318
expect(ui()).toHaveNthLogged(

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export function yargsGlobalOptionsDefinition(): Record<
1313
},
1414
verbose: {
1515
describe:
16-
'When true creates more verbose output. This is helpful when debugging.',
16+
'When true creates more verbose output. This is helpful when debugging. You may also set CP_VERBOSE env variable instead.',
1717
type: 'boolean',
1818
default: false,
1919
},

packages/cli/src/lib/implementation/validate-filter-options.utils.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { PluginConfig } from '@code-pushup/models';
22
import {
33
capitalize,
44
filterItemRefsBy,
5+
isVerbose,
56
pluralize,
67
ui,
78
} from '@code-pushup/utils';
@@ -16,8 +17,7 @@ export function validateFilterOption(
1617
{
1718
itemsToFilter,
1819
skippedItems,
19-
verbose,
20-
}: { itemsToFilter: string[]; skippedItems: string[]; verbose: boolean },
20+
}: { itemsToFilter: string[]; skippedItems: string[] },
2121
): void {
2222
const validItems = isCategoryOption(option)
2323
? categories.map(({ slug }) => slug)
@@ -51,14 +51,14 @@ export function validateFilterOption(
5151
}
5252
ui().logger.warning(message);
5353
}
54-
if (skippedValidItems.length > 0 && verbose) {
54+
if (skippedValidItems.length > 0 && isVerbose()) {
5555
const item = getItemType(option, skippedValidItems.length);
5656
const prefix = skippedValidItems.length === 1 ? `a skipped` : `skipped`;
5757
ui().logger.warning(
5858
`The --${option} argument references ${prefix} ${item}: ${skippedValidItems.join(', ')}.`,
5959
);
6060
}
61-
if (isPluginOption(option) && categories.length > 0 && verbose) {
61+
if (isPluginOption(option) && categories.length > 0 && isVerbose()) {
6262
const removedCategories = filterItemRefsBy(categories, ({ plugin }) =>
6363
isOnlyOption(option)
6464
? !itemsToFilterSet.has(plugin)
@@ -78,12 +78,11 @@ export function validateFilterOption(
7878
export function validateSkippedCategories(
7979
originalCategories: NonNullable<Filterables['categories']>,
8080
filteredCategories: NonNullable<Filterables['categories']>,
81-
verbose: boolean,
8281
): void {
8382
const skippedCategories = originalCategories.filter(
8483
original => !filteredCategories.some(({ slug }) => slug === original.slug),
8584
);
86-
if (skippedCategories.length > 0 && verbose) {
85+
if (skippedCategories.length > 0 && isVerbose()) {
8786
skippedCategories.forEach(category => {
8887
ui().logger.info(
8988
`Category ${category.slug} was removed because all its refs were skipped. Affected refs: ${category.refs

packages/cli/src/lib/implementation/validate-filter-options.utils.unit.test.ts

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ describe('validateFilterOption', () => {
4848
{ slug: 'c1', refs: [{ plugin: 'p1', slug: 'a1-p1' }] },
4949
] as CategoryConfig[],
5050
},
51-
{ itemsToFilter, skippedItems: [], verbose: false },
51+
{ itemsToFilter, skippedItems: [] },
5252
);
5353
expect(ui()).toHaveLogged('warn', expected);
5454
},
@@ -91,7 +91,7 @@ describe('validateFilterOption', () => {
9191
},
9292
] as CategoryConfig[],
9393
},
94-
{ itemsToFilter, skippedItems: [], verbose: false },
94+
{ itemsToFilter, skippedItems: [] },
9595
);
9696
expect(ui()).toHaveLogged('warn', expected);
9797
},
@@ -106,12 +106,14 @@ describe('validateFilterOption', () => {
106106
{ slug: 'p2', audits: [{ slug: 'a1-p2' }] },
107107
] as PluginConfig[],
108108
},
109-
{ itemsToFilter: ['p1'], skippedItems: [], verbose: false },
109+
{ itemsToFilter: ['p1'], skippedItems: [] },
110110
);
111111
expect(ui()).not.toHaveLogs();
112112
});
113113

114114
it('should log a category ignored as a result of plugin filtering', () => {
115+
vi.stubEnv('CP_VERBOSE', 'true');
116+
115117
validateFilterOption(
116118
'onlyPlugins',
117119
{
@@ -125,7 +127,7 @@ describe('validateFilterOption', () => {
125127
{ slug: 'c3', refs: [{ plugin: 'p2' }] },
126128
] as CategoryConfig[],
127129
},
128-
{ itemsToFilter: ['p1'], skippedItems: [], verbose: true },
130+
{ itemsToFilter: ['p1'], skippedItems: [] },
129131
);
130132
expect(ui()).toHaveLoggedTimes(1);
131133
expect(ui()).toHaveLogged(
@@ -145,7 +147,7 @@ describe('validateFilterOption', () => {
145147
{ slug: 'p3', audits: [{ slug: 'a1-p3' }] },
146148
] as PluginConfig[],
147149
},
148-
{ itemsToFilter: ['p4', 'p5'], skippedItems: [], verbose: false },
150+
{ itemsToFilter: ['p4', 'p5'], skippedItems: [] },
149151
);
150152
}).toThrow(
151153
new OptionValidationError(
@@ -164,12 +166,12 @@ describe('validateFilterOption', () => {
164166
validateFilterOption(
165167
'skipPlugins',
166168
{ plugins: allPlugins },
167-
{ itemsToFilter: ['plugin1'], skippedItems: [], verbose: false },
169+
{ itemsToFilter: ['plugin1'], skippedItems: [] },
168170
);
169171
validateFilterOption(
170172
'onlyPlugins',
171173
{ plugins: allPlugins },
172-
{ itemsToFilter: ['plugin3'], skippedItems: [], verbose: false },
174+
{ itemsToFilter: ['plugin3'], skippedItems: [] },
173175
);
174176
}).toThrow(
175177
new OptionValidationError(
@@ -178,7 +180,7 @@ describe('validateFilterOption', () => {
178180
);
179181
});
180182

181-
it('should throw OptionValidationError when none of the onlyCatigories are valid', () => {
183+
it('should throw OptionValidationError when none of the onlyCategories are valid', () => {
182184
expect(() => {
183185
validateFilterOption(
184186
'onlyCategories',
@@ -197,7 +199,7 @@ describe('validateFilterOption', () => {
197199
},
198200
] as CategoryConfig[],
199201
},
200-
{ itemsToFilter: ['c2', 'c3'], skippedItems: [], verbose: false },
202+
{ itemsToFilter: ['c2', 'c3'], skippedItems: [] },
201203
);
202204
}).toThrow(
203205
new OptionValidationError(
@@ -207,6 +209,8 @@ describe('validateFilterOption', () => {
207209
});
208210

209211
it('should log skipped items if verbose mode is enabled', () => {
212+
vi.stubEnv('CP_VERBOSE', 'true');
213+
210214
const plugins = [
211215
{ slug: 'p1', audits: [{ slug: 'a1-p1' }] },
212216
] as PluginConfig[];
@@ -217,7 +221,7 @@ describe('validateFilterOption', () => {
217221
validateFilterOption(
218222
'skipPlugins',
219223
{ plugins, categories },
220-
{ itemsToFilter: ['p1'], skippedItems: ['p1'], verbose: true },
224+
{ itemsToFilter: ['p1'], skippedItems: ['p1'] },
221225
);
222226
expect(ui()).toHaveNthLogged(
223227
1,
@@ -450,16 +454,14 @@ describe('validateSkippedCategories', () => {
450454
] as NonNullable<Filterables['categories']>;
451455

452456
it('should log info when categories are removed', () => {
453-
validateSkippedCategories(
454-
categories,
455-
[
456-
{
457-
slug: 'c2',
458-
refs: [{ type: 'audit', plugin: 'p2', slug: 'a1', weight: 1 }],
459-
},
460-
] as NonNullable<Filterables['categories']>,
461-
true,
462-
);
457+
vi.stubEnv('CP_VERBOSE', 'true');
458+
459+
validateSkippedCategories(categories, [
460+
{
461+
slug: 'c2',
462+
refs: [{ type: 'audit', plugin: 'p2', slug: 'a1', weight: 1 }],
463+
},
464+
] as NonNullable<Filterables['categories']>);
463465
expect(ui()).toHaveLogged(
464466
'info',
465467
'Category c1 was removed because all its refs were skipped. Affected refs: g1 (group)',
@@ -468,12 +470,12 @@ describe('validateSkippedCategories', () => {
468470

469471
it('should not log anything when categories are not removed', () => {
470472
const loggerSpy = vi.spyOn(ui().logger, 'info');
471-
validateSkippedCategories(categories, categories, true);
473+
validateSkippedCategories(categories, categories);
472474
expect(loggerSpy).not.toHaveBeenCalled();
473475
});
474476

475477
it('should throw an error when no categories remain after filtering', () => {
476-
expect(() => validateSkippedCategories(categories, [], false)).toThrow(
478+
expect(() => validateSkippedCategories(categories, [])).toThrow(
477479
new OptionValidationError(
478480
'No categories remain after filtering. Removed categories: c1, c2',
479481
),

packages/core/src/lib/collect-and-persist.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@ import {
33
type PersistConfig,
44
pluginReportSchema,
55
} from '@code-pushup/models';
6-
import { logStdoutSummary, scoreReport, sortReport } from '@code-pushup/utils';
6+
import {
7+
isVerbose,
8+
logStdoutSummary,
9+
scoreReport,
10+
sortReport,
11+
} from '@code-pushup/utils';
712
import { collect } from './implementation/collect.js';
813
import {
914
logPersistedResults,
@@ -29,9 +34,9 @@ export async function collectAndPersistReports(
2934
);
3035

3136
// terminal output
32-
logStdoutSummary(sortedScoredReport, options.verbose);
37+
logStdoutSummary(sortedScoredReport);
3338

34-
if (options.verbose) {
39+
if (isVerbose()) {
3540
logPersistedResults(persistResults);
3641
}
3742

0 commit comments

Comments
 (0)