Skip to content

Commit 3d0d805

Browse files
committed
chore: event changes and minor improvements
1 parent 6a9dd64 commit 3d0d805

File tree

3 files changed

+22
-21
lines changed

3 files changed

+22
-21
lines changed

src/commands/scan/eol.ts

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -57,30 +57,27 @@ export default class ScanEol extends Command {
5757
public async run(): Promise<EolReport | undefined> {
5858
const { flags } = await this.parse(ScanEol);
5959

60-
if (!flags.file) {
61-
track('CLI SBOM Generation Started', (context) => ({
62-
command: context.command,
63-
command_flags: context.command_flags,
64-
scan_location: flags.dir,
65-
}));
66-
}
60+
track('CLI EOL Scan Started', (context) => ({
61+
command: context.command,
62+
command_flags: context.command_flags,
63+
scan_location: flags.dir,
64+
}));
6765

6866
const sbomStartTime = performance.now();
6967
const sbom = await this.loadSbom();
7068
const sbomEndTime = performance.now();
7169

7270
if (!flags.file) {
73-
track('CLI SBOM Generation Completed', (context) => ({
71+
track('CLI SBOM Generated', (context) => ({
7472
command: context.command,
7573
command_flags: context.command_flags,
7674
scan_location: flags.dir,
77-
sbom_created: true,
78-
sbom_load_time: (sbomEndTime - sbomStartTime) / 1000,
75+
sbom_generation_time: (sbomEndTime - sbomStartTime) / 1000,
7976
}));
8077
}
8178

8279
if (!sbom.components?.length) {
83-
track('CLI No Components Found, Report Not Generated', (context) => ({
80+
track('CLI EOL Scan Ended, No Components Found', (context) => ({
8481
command: context.command,
8582
command_flags: context.command_flags,
8683
scan_location: flags.dir,
@@ -89,12 +86,6 @@ export default class ScanEol extends Command {
8986
return;
9087
}
9188

92-
track('CLI EOL Scan Started', (context) => ({
93-
command: context.command,
94-
command_flags: context.command_flags,
95-
scan_location: flags.dir,
96-
}));
97-
9889
const scanStartTime = performance.now();
9990
const scan = await this.scanSbom(sbom);
10091
const scanEndTime = performance.now();

src/hooks/finally.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,18 @@ import type { Hook } from '@oclif/core';
22
import ora from 'ora';
33
import { track } from '../service/analytics.svc.ts';
44

5-
const hook: Hook<'finally'> = async () => {
5+
const hook: Hook<'finally'> = async (opts) => {
66
const spinner = ora().start('Cleaning up');
7-
track('CLI Session Ended', (context) => ({
7+
const event = track('CLI Session Ended', (context) => ({
88
cli_version: context.cli_version,
99
ended_at: new Date(),
10-
})).promise.then(() => spinner.stop());
10+
})).promise;
11+
12+
if (!opts.argv.includes('--help')) {
13+
await event;
14+
}
15+
16+
spinner.stop();
1117
};
1218

1319
export default hook;

src/hooks/prerun.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
import { parseArgs } from 'node:util';
12
import type { Hook } from '@oclif/core';
23
import debug from 'debug';
34
import { initializeAnalytics, track } from '../service/analytics.svc.ts';
45

56
const hook: Hook<'prerun'> = async (opts) => {
7+
const args = parseArgs({ allowPositionals: true, strict: false });
68
initializeAnalytics();
7-
track('CLI Session Started', (context) => ({
9+
track('CLI Command Submitted', (context) => ({
10+
command: args.positionals.join(' ').trim(),
11+
command_flags: Object.entries(args.values).flat().join(' '),
812
app_used: context.app_used,
913
ci_provider: context.ci_provider,
1014
cli_version: context.cli_version,

0 commit comments

Comments
 (0)