diff --git a/src/cmds/login.ts b/src/cmds/login.ts index 887712ce3..4fb386248 100644 --- a/src/cmds/login.ts +++ b/src/cmds/login.ts @@ -1,4 +1,4 @@ -import type { CommandOptions } from '../lib/baseCommand'; +import type { ZeroAuthCommandOptions } from '../lib/baseCommand'; import prompts from 'prompts'; @@ -45,7 +45,7 @@ export default class LoginCommand extends Command { ]; } - async run(opts: CommandOptions) { + async run(opts: ZeroAuthCommandOptions) { await super.run(opts); prompts.override(opts); diff --git a/src/cmds/logout.ts b/src/cmds/logout.ts index 377bb79ab..4f6d93640 100644 --- a/src/cmds/logout.ts +++ b/src/cmds/logout.ts @@ -1,4 +1,4 @@ -import type { CommandOptions } from '../lib/baseCommand'; +import type { ZeroAuthCommandOptions } from '../lib/baseCommand'; import Command, { CommandCategories } from '../lib/baseCommand'; import config from '../lib/config'; @@ -16,7 +16,7 @@ export default class LogoutCommand extends Command { this.args = []; } - async run(opts: CommandOptions<{}>) { + async run(opts: ZeroAuthCommandOptions<{}>) { await super.run(opts); if (configStore.has('email') && configStore.has('project')) { diff --git a/src/cmds/oas.ts b/src/cmds/oas.ts index 1b617926c..889e5a388 100644 --- a/src/cmds/oas.ts +++ b/src/cmds/oas.ts @@ -1,4 +1,4 @@ -import type { CommandOptions } from '../lib/baseCommand'; +import type { ZeroAuthCommandOptions } from '../lib/baseCommand'; import Command, { CommandCategories } from '../lib/baseCommand'; import isHidden from '../lib/decorators/isHidden'; @@ -16,7 +16,7 @@ export default class OASCommand extends Command { this.args = []; } - async run(opts: CommandOptions<{}>) { + async run(opts: ZeroAuthCommandOptions<{}>) { await super.run(opts); const message = [ diff --git a/src/cmds/open.ts b/src/cmds/open.ts index 17ecce073..7d29c3e16 100644 --- a/src/cmds/open.ts +++ b/src/cmds/open.ts @@ -1,4 +1,4 @@ -import type { CommandOptions } from '../lib/baseCommand'; +import type { ZeroAuthCommandOptions } from '../lib/baseCommand'; import chalk from 'chalk'; import open from 'open'; @@ -31,7 +31,7 @@ export default class OpenCommand extends Command { ]; } - async run(opts: CommandOptions) { + async run(opts: ZeroAuthCommandOptions) { await super.run(opts); const { dash } = opts; diff --git a/src/cmds/openapi/convert.ts b/src/cmds/openapi/convert.ts index 78aabe96e..765bf3912 100644 --- a/src/cmds/openapi/convert.ts +++ b/src/cmds/openapi/convert.ts @@ -1,4 +1,4 @@ -import type { CommandOptions } from '../../lib/baseCommand'; +import type { ZeroAuthCommandOptions } from '../../lib/baseCommand'; import type { OASDocument } from 'oas/dist/rmoas.types'; import fs from 'fs'; @@ -43,7 +43,7 @@ export default class OpenAPIConvertCommand extends Command { ]; } - async run(opts: CommandOptions) { + async run(opts: ZeroAuthCommandOptions) { await super.run(opts); const { spec, workingDirectory } = opts; diff --git a/src/cmds/openapi/inspect.ts b/src/cmds/openapi/inspect.ts index c1297808b..388fca366 100644 --- a/src/cmds/openapi/inspect.ts +++ b/src/cmds/openapi/inspect.ts @@ -1,5 +1,5 @@ import type { Analysis, AnalyzedFeature } from '../../lib/analyzeOas'; -import type { CommandOptions } from '../../lib/baseCommand'; +import type { ZeroAuthCommandOptions } from '../../lib/baseCommand'; import type { OASDocument } from 'oas/dist/rmoas.types'; import chalk from 'chalk'; @@ -215,7 +215,7 @@ export default class OpenAPIInspectCommand extends Command { return report.join('\n'); } - async run(opts: CommandOptions) { + async run(opts: ZeroAuthCommandOptions) { await super.run(opts); const { spec, workingDirectory, feature: features } = opts; diff --git a/src/cmds/openapi/reduce.ts b/src/cmds/openapi/reduce.ts index 3581bb3b6..46cd4d4a9 100644 --- a/src/cmds/openapi/reduce.ts +++ b/src/cmds/openapi/reduce.ts @@ -1,4 +1,4 @@ -import type { CommandOptions } from '../../lib/baseCommand'; +import type { ZeroAuthCommandOptions } from '../../lib/baseCommand'; import type { OASDocument } from 'oas/dist/rmoas.types'; import fs from 'fs'; @@ -70,7 +70,7 @@ export default class OpenAPIReduceCommand extends Command { ]; } - async run(opts: CommandOptions) { + async run(opts: ZeroAuthCommandOptions) { await super.run(opts); const { spec, title, workingDirectory } = opts; diff --git a/src/cmds/openapi/validate.ts b/src/cmds/openapi/validate.ts index dcbecf22a..cb92be1f1 100644 --- a/src/cmds/openapi/validate.ts +++ b/src/cmds/openapi/validate.ts @@ -1,4 +1,4 @@ -import type { CommandOptions } from '../../lib/baseCommand'; +import type { ZeroAuthCommandOptions } from '../../lib/baseCommand'; import chalk from 'chalk'; @@ -32,7 +32,7 @@ export default class OpenAPIValidateCommand extends Command { ]; } - async run(opts: CommandOptions) { + async run(opts: ZeroAuthCommandOptions) { await super.run(opts); const { spec, workingDirectory } = opts; @@ -45,7 +45,7 @@ export default class OpenAPIValidateCommand extends Command { const { specPath, specType } = await prepareOas(spec, 'openapi:validate'); return Promise.resolve(chalk.green(`${specPath} is a valid ${specType} API definition!`)).then(msg => - createGHA(msg, this.command, this.args, { ...opts, spec: specPath } as CommandOptions), + createGHA(msg, this.command, this.args, { ...opts, spec: specPath } as ZeroAuthCommandOptions), ); } } diff --git a/src/cmds/validate.ts b/src/cmds/validate.ts index fb4839a52..3c8fb1f70 100644 --- a/src/cmds/validate.ts +++ b/src/cmds/validate.ts @@ -1,5 +1,5 @@ import type { Options } from './openapi/validate'; -import type { CommandOptions } from '../lib/baseCommand'; +import type { ZeroAuthCommandOptions } from '../lib/baseCommand'; import Command from '../lib/baseCommand'; import isHidden from '../lib/decorators/isHidden'; @@ -16,7 +16,7 @@ export default class ValidateAliasCommand extends OpenAPIValidateCommand { this.description = 'Alias for `rdme openapi:validate` [deprecated].'; } - async run(opts: CommandOptions) { + async run(opts: ZeroAuthCommandOptions) { Command.warn('`rdme validate` has been deprecated. Please use `rdme openapi:validate` instead.'); return super.run(opts); } diff --git a/src/cmds/whoami.ts b/src/cmds/whoami.ts index d43df443b..c3e0fc7ab 100644 --- a/src/cmds/whoami.ts +++ b/src/cmds/whoami.ts @@ -1,4 +1,4 @@ -import type { CommandOptions } from '../lib/baseCommand'; +import type { ZeroAuthCommandOptions } from '../lib/baseCommand'; import chalk from 'chalk'; @@ -18,7 +18,7 @@ export default class WhoAmICommand extends Command { this.args = []; } - async run(opts: CommandOptions<{}>) { + async run(opts: ZeroAuthCommandOptions<{}>) { await super.run(opts); const { email, project } = getCurrentConfig(); diff --git a/src/index.ts b/src/index.ts index 1f49c4e86..aad0bb4e1 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,6 @@ /* eslint-disable no-underscore-dangle */ import type Command from './lib/baseCommand'; -import type { CommandOptions, AuthenticatedCommandOptions } from './lib/baseCommand'; +import type { CommandOptions } from './lib/baseCommand'; import type { CommandLineOptions } from 'command-line-args'; import chalk from 'chalk'; @@ -83,7 +83,7 @@ export default function rdme(rawProcessArgv: NodeJS.Process['argv']) { } try { - let cmdArgv: CommandOptions<{}> | AuthenticatedCommandOptions<{}> | CommandLineOptions; + let cmdArgv: CommandOptions<{}> | CommandLineOptions; let bin: Command; // Handling for `rdme help` and `rdme help ` cases. @@ -135,9 +135,9 @@ export default function rdme(rawProcessArgv: NodeJS.Process['argv']) { cmdArgv = { key, ...cmdArgv }; - return bin.run(cmdArgv as CommandOptions<{}> | AuthenticatedCommandOptions<{}>).then((msg: string) => { + return bin.run(cmdArgv as CommandOptions<{}>).then((msg: string) => { if (bin.supportsGHA) { - return createGHA(msg, bin.command, bin.args, cmdArgv as CommandOptions<{}> | AuthenticatedCommandOptions<{}>); + return createGHA(msg, bin.command, bin.args, cmdArgv as CommandOptions<{}>); } return msg; }); diff --git a/src/lib/baseCommand.ts b/src/lib/baseCommand.ts index 115d1e24a..f6c7af221 100644 --- a/src/lib/baseCommand.ts +++ b/src/lib/baseCommand.ts @@ -10,15 +10,17 @@ import isCI from './isCI'; import { debug, info, warn } from './logger'; import loginFlow from './loginFlow'; -export type CommandOptions = T & { - github?: boolean; -} & { key?: never }; +export type CommandOptions = ZeroAuthCommandOptions | AuthenticatedCommandOptions; -export type AuthenticatedCommandOptions = Omit, 'key'> & { +export type AuthenticatedCommandOptions = Omit, 'key'> & { key: string; version?: string; }; +export type ZeroAuthCommandOptions = T & { + github?: boolean; +} & { key?: never }; + export enum CommandCategories { ADMIN = 'admin', APIS = 'apis', @@ -86,7 +88,7 @@ export default class Command { */ args!: OptionDefinition[]; - async run(opts: CommandOptions<{}> | AuthenticatedCommandOptions<{}>): Promise { + async run(opts: CommandOptions<{}>): Promise { Command.debug(`command: ${this.command}`); Command.debug(`opts: ${JSON.stringify(opts)}`); diff --git a/src/lib/createGHA/index.ts b/src/lib/createGHA/index.ts index f0bdba0d3..32edd5f19 100644 --- a/src/lib/createGHA/index.ts +++ b/src/lib/createGHA/index.ts @@ -1,5 +1,5 @@ import type commands from '../../cmds'; -import type { AuthenticatedCommandOptions, CommandOptions } from '../baseCommand'; +import type { CommandOptions } from '../baseCommand'; import type { OptionDefinition } from 'command-line-usage'; import fs from 'fs'; @@ -48,7 +48,7 @@ export const getGHAFileName = (fileName: string) => { * Returns a redacted `key` if the current command uses authentication. * Otherwise, returns `false`. */ -function getKey(args: OptionDefinition[], opts: CommandOptions<{}> | AuthenticatedCommandOptions<{}>): string | false { +function getKey(args: OptionDefinition[], opts: CommandOptions<{}>): string | false { if (args.some(arg => arg.name === 'key')) { return `••••••••••••${opts.key?.slice(-5) || ''}`; } @@ -61,7 +61,7 @@ function getKey(args: OptionDefinition[], opts: CommandOptions<{}> | Authenticat function constructCmdString( command: keyof typeof commands, args: OptionDefinition[], - opts: CommandOptions<{}> | AuthenticatedCommandOptions<{}>, + opts: CommandOptions<{}>, ): string { const optsString = args .sort(arg => (arg.defaultOption ? -1 : 0)) @@ -153,7 +153,7 @@ export default async function createGHA( msg: string, command: keyof typeof commands, args: OptionDefinition[], - opts: CommandOptions<{}> | AuthenticatedCommandOptions<{}>, + opts: CommandOptions<{}>, ) { debug(`running GHA onboarding for ${command} command`); debug(`opts used in createGHA: ${JSON.stringify(opts)}`);