diff --git a/src/commands/analytics.ts b/src/commands/analytics.ts index a74c20bf..6d2d427e 100644 --- a/src/commands/analytics.ts +++ b/src/commands/analytics.ts @@ -4,7 +4,7 @@ import contrib from 'blessed-contrib' import meow from 'meow' import ora from 'ora' -import { outputFlags, validationFlags } from '../flags' +import { outputFlags } from '../flags' import { handleApiCall, handleUnsuccessfulApiResponse } from '../utils/api-helpers' import { AuthError, InputError } from '../utils/errors' import { printFlagList } from '../utils/formatting' @@ -12,9 +12,11 @@ import { getDefaultKey, setupSdk } from '../utils/sdk' import type { CliSubcommand } from '../utils/meow-with-subcommands' import type { Ora } from "ora" +import chalk from 'chalk' export const analytics: CliSubcommand = { - description: 'Look up analytics data', + description: `Look up analytics data \n + Default parameters are set to show the organization-level analytics over the last 7 days.`, async run (argv, importMeta, { parentName }) { const name = parentName + ' analytics' @@ -36,31 +38,53 @@ export const analytics: CliSubcommand = { } } +const analyticsFlags: { [key: string]: any } = { + scope: { + type: 'string', + shortFlag: 's', + default: 'org', + description: "Scope of the analytics data - either 'org' or 'repo'" + }, + time: { + type: 'number', + shortFlag: 't', + default: 7, + description: 'Time filter - either 7, 30 or 90' + }, + repo: { + type: 'string', + shortFlag: 'r', + default: '', + description: "Name of the repository" + }, +} + // Internal functions type CommandContext = { scope: string - time: string - repo: string | undefined + time: number + repo: string outputJson: boolean } function setupCommand (name: string, description: string, argv: readonly string[], importMeta: ImportMeta): void|CommandContext { const flags: { [key: string]: any } = { ...outputFlags, - ...validationFlags, + ...analyticsFlags } const cli = meow(` Usage - $ ${name}