Skip to content

Commit bf45226

Browse files
authored
feat: adds --hideReportUrl flag to allow the users to hide the URL report creation #366. (#380)
* feat: adds --hideReportUrl flag to allow the users to hide the URL report creation #366 * feat: adds suggested variable for console display separator width
1 parent f4a7bfa commit bf45226

5 files changed

Lines changed: 47 additions & 7 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,13 @@ Scan a given SBOM for EOL data
112112

113113
```
114114
USAGE
115-
$ hd scan eol [--json] [-f <value> | -d <value>] [-s] [--saveSbom] [--saveTrimmedSbom] [--version]
115+
$ hd scan eol [--json] [-f <value> | -d <value>] [-s] [--saveSbom] [--saveTrimmedSbom] [--hideReportUrl] [--version]
116116
117117
FLAGS
118118
-d, --dir=<value> [default: <current directory>] The directory to scan in order to create a cyclonedx SBOM
119119
-f, --file=<value> The file path of an existing cyclonedx SBOM to scan for EOL
120120
-s, --save Save the generated report as herodevs.report.json in the scanned directory
121+
--hideReportUrl Hide the generated web report URL for this scan
121122
--saveSbom Save the generated SBOM as herodevs.sbom.json in the scanned directory
122123
--saveTrimmedSbom Save the trimmed SBOM as herodevs.sbom-trimmed.json in the scanned directory
123124
--version Show CLI version.

e2e/scan/eol.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,13 @@ describe('scan:eol e2e', () => {
326326
const { stdout } = await run(cmd);
327327
doesNotMatch(stdout, /View your full EOL report/, 'Should not show web report text in JSON output');
328328
});
329+
330+
it('shows save hint when --hideReportUrl flag is used', async () => {
331+
const cmd = `scan:eol --file ${simpleSbom} --hideReportUrl`;
332+
const { stdout } = await run(cmd);
333+
doesNotMatch(stdout, /View your full EOL report/, 'Should not show web report text when hidden');
334+
match(stdout, /To save your detailed JSON report, use the --save flag/, 'Should show save hint message');
335+
});
329336
});
330337

331338
describe('privacy and transparency', () => {

src/commands/scan/eol.ts

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { createSbom } from '../../service/cdx.svc.ts';
99
import {
1010
countComponentsByStatus,
1111
formatDataPrivacyLink,
12+
formatReportSaveHint,
1213
formatScanResults,
1314
formatWebReportUrl,
1415
} from '../../service/display.svc.ts';
@@ -68,6 +69,11 @@ export default class ScanEol extends Command {
6869
default: false,
6970
description: `Save the trimmed SBOM as ${filenamePrefix}.sbom-trimmed.json in the scanned directory`,
7071
}),
72+
hideReportUrl: Flags.boolean({
73+
aliases: ['hide-report-url'],
74+
default: false,
75+
description: 'Hide the generated web report URL for this scan',
76+
}),
7177
version: Flags.version(),
7278
};
7379

@@ -125,7 +131,8 @@ export default class ScanEol extends Command {
125131
sbom_created: !flags.file,
126132
scan_load_time: (scanEndTime - scanStartTime) / 1000,
127133
scanned_ecosystems: componentCounts.ECOSYSTEMS,
128-
web_report_link: scan.id ? `${config.eolReportUrl}/${scan.id}` : undefined,
134+
web_report_link: !flags.hideReportUrl && scan.id ? `${config.eolReportUrl}/${scan.id}` : undefined,
135+
web_report_hidden: flags.hideReportUrl,
129136
}));
130137

131138
if (flags.save) {
@@ -139,7 +146,7 @@ export default class ScanEol extends Command {
139146
}
140147

141148
if (!this.jsonEnabled()) {
142-
this.displayResults(scan);
149+
this.displayResults(scan, flags.hideReportUrl);
143150
}
144151

145152
return scan;
@@ -225,17 +232,22 @@ export default class ScanEol extends Command {
225232
}
226233
}
227234

228-
private displayResults(report: EolReport): void {
235+
private displayResults(report: EolReport, hideReportUrl: boolean): void {
229236
const lines = formatScanResults(report);
230237
for (const line of lines) {
231238
this.log(line);
232239
}
233240

234-
if (report.id) {
241+
if (!hideReportUrl && report.id) {
235242
const lines = formatWebReportUrl(report.id, config.eolReportUrl);
236243
for (const line of lines) {
237244
this.log(line);
238245
}
246+
} else if (hideReportUrl) {
247+
const lines = formatReportSaveHint();
248+
for (const line of lines) {
249+
this.log(line);
250+
}
239251
}
240252

241253
const privacyLines = formatDataPrivacyLink();

src/service/display.svc.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ const STATUS_COLORS: Record<ComponentStatus, string> = {
1010
EOL_UPCOMING: 'yellow',
1111
};
1212

13+
const SEPARATOR_WIDTH = 40;
14+
1315
/**
1416
* Formats status row text with appropriate color and icon
1517
*/
@@ -72,7 +74,7 @@ export function formatScanResults(report: EolReport): string[] {
7274

7375
return [
7476
ux.colorize('bold', 'Scan results:'),
75-
ux.colorize('bold', '-'.repeat(40)),
77+
ux.colorize('bold', '-'.repeat(SEPARATOR_WIDTH)),
7678
ux.colorize('bold', `${report.components.length.toLocaleString()} total packages scanned`),
7779
getStatusRowText.EOL(`${EOL.toLocaleString().padEnd(5)} End-of-Life (EOL)`),
7880
getStatusRowText.EOL_UPCOMING(`${EOL_UPCOMING.toLocaleString().padEnd(5)} EOL Upcoming`),
@@ -93,7 +95,7 @@ export function formatWebReportUrl(id: string, reportCardUrl: string): string[]
9395
terminalLink(new URL(reportCardUrl).hostname, `${reportCardUrl}/${id}`, { fallback: (_, url) => url }),
9496
);
9597

96-
return [ux.colorize('bold', '-'.repeat(40)), `🌐 View your full EOL report at: ${url}\n`];
98+
return [ux.colorize('bold', '-'.repeat(SEPARATOR_WIDTH)), `🌐 View your full EOL report at: ${url}\n`];
9799
}
98100

99101
/**
@@ -108,3 +110,10 @@ export function formatDataPrivacyLink(): string[] {
108110

109111
return [`🔒 ${link}\n`];
110112
}
113+
114+
/**
115+
* Formats the report save hint for console display when the web report URL is hidden
116+
*/
117+
export function formatReportSaveHint(): string[] {
118+
return [ux.colorize('bold', '-'.repeat(SEPARATOR_WIDTH)), 'To save your detailed JSON report, use the --save flag'];
119+
}

test/service/display.svc.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { EolReport } from '@herodevs/eol-shared';
44
import {
55
countComponentsByStatus,
66
formatDataPrivacyLink,
7+
formatReportSaveHint,
78
formatScanResults,
89
formatWebReportUrl,
910
} from '../../src/service/display.svc.ts';
@@ -169,4 +170,14 @@ describe('display.svc', () => {
169170
assert.ok(lines[0].includes('docs.herodevs.com/eol-ds/data-privacy-and-security'));
170171
});
171172
});
173+
174+
describe('formatReportSaveHint', () => {
175+
it('should provide a save hint message', () => {
176+
const lines = formatReportSaveHint();
177+
178+
assert.strictEqual(lines.length, 2);
179+
assert.ok(lines[0].includes('-'.repeat(40)));
180+
assert.ok(lines[1].includes('--save'));
181+
});
182+
});
172183
});

0 commit comments

Comments
 (0)