From 2bd8b599283f4dfd8700caf22f16e50124ec6683 Mon Sep 17 00:00:00 2001 From: Peter van der Zee Date: Thu, 13 Feb 2025 15:31:49 +0100 Subject: [PATCH] Refactor the analytics command --- src/cli.ts | 2 +- src/commands/analytics/analytics-command.ts | 112 ++++++++ .../run-analytics.ts} | 259 +++++------------- src/commands/types.ts | 7 + src/flags.ts | 19 +- src/utils/fs.ts | 2 +- src/utils/meow-with-subcommands.ts | 13 +- 7 files changed, 219 insertions(+), 195 deletions(-) create mode 100644 src/commands/analytics/analytics-command.ts rename src/commands/{analytics.ts => analytics/run-analytics.ts} (64%) create mode 100644 src/commands/types.ts diff --git a/src/cli.ts b/src/cli.ts index c847b1820..d4970c20b 100755 --- a/src/cli.ts +++ b/src/cli.ts @@ -8,7 +8,7 @@ import updateNotifier from 'tiny-updater' import colors from 'yoctocolors-cjs' import { actionCommand } from './commands/action' -import { analyticsCommand } from './commands/analytics' +import { analyticsCommand } from './commands/analytics/analytics-command' import { auditLogCommand } from './commands/audit-log' import { cdxgenCommand } from './commands/cdxgen' import { dependenciesCommand } from './commands/dependencies' diff --git a/src/commands/analytics/analytics-command.ts b/src/commands/analytics/analytics-command.ts new file mode 100644 index 000000000..3a44f0765 --- /dev/null +++ b/src/commands/analytics/analytics-command.ts @@ -0,0 +1,112 @@ +import meowOrDie from 'meow' +import colors from 'yoctocolors-cjs' + +import { runAnalytics } from './run-analytics.ts' +import { commonFlags, outputFlags } from '../../flags' +import { AuthError, InputError } from '../../utils/errors' +import { getFlagListOutput } from '../../utils/output-formatting' +import { getDefaultToken } from '../../utils/sdk.ts' + +import type { CliCommandConfig } from '../../utils/meow-with-subcommands' +import type { CommandContext } from '../types.ts' + +const config: CliCommandConfig = { + commandName: 'analytics', + description: `Look up analytics data`, + hidden: false, + flags: { + ...commonFlags, + ...outputFlags, + scope: { + type: 'string', + shortFlag: 's', + default: 'org', + description: + "Scope of the analytics data - either 'org' or 'repo', default: org" + }, + time: { + type: 'number', + shortFlag: 't', + default: 7, + description: 'Time filter - either 7, 30 or 90, default: 7' + }, + repo: { + type: 'string', + shortFlag: 'r', + default: '', + description: 'Name of the repository' + }, + file: { + type: 'string', + shortFlag: 'f', + default: '', + description: 'Path to a local file to save the output' + } + }, + help: (parentName, { commandName, flags }) => ` + Usage + $ ${parentName} ${commandName} --scope= --time=