From ea7e721a6863b1baa2193974e0167ccdcaeeaaf7 Mon Sep 17 00:00:00 2001 From: qun <68707557+L-Qun@users.noreply.github.com> Date: Fri, 1 Mar 2024 12:30:22 +0000 Subject: [PATCH 1/2] chore: add help alias and enable strict mode --- apps/sparo-lib/src/cli/commands/help.ts | 15 ++++++++++----- apps/sparo-lib/src/services/ArgvService.ts | 2 ++ common/changes/sparo/main_2024-03-01-12-30.json | 10 ++++++++++ 3 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 common/changes/sparo/main_2024-03-01-12-30.json diff --git a/apps/sparo-lib/src/cli/commands/help.ts b/apps/sparo-lib/src/cli/commands/help.ts index cdbdf46..307fb95 100644 --- a/apps/sparo-lib/src/cli/commands/help.ts +++ b/apps/sparo-lib/src/cli/commands/help.ts @@ -1,6 +1,8 @@ import { Command } from '../../decorator'; import type { Argv } from 'yargs'; import type { ICommand } from './base'; +import { ArgvService } from '../../services/ArgvService'; +import { inject } from 'inversify'; export interface IHelpCommandOptions {} @@ -8,14 +10,17 @@ export interface IHelpCommandOptions {} export class HelpCommand implements ICommand { public cmd: string = 'help'; public description: string = ''; - private _yargs: Argv | undefined; - public builder = (yargs: Argv): void => { - this._yargs = yargs; - }; + @inject(ArgvService) private _yargs!: ArgvService; + + public builder(yargs: Argv<{}>): void { + yargs.help(false); + } + public handler = async (): Promise => { - this._yargs?.showHelp(); + this._yargs.yargsArgv.showHelp(); }; + public getHelp(): string { return ''; } diff --git a/apps/sparo-lib/src/services/ArgvService.ts b/apps/sparo-lib/src/services/ArgvService.ts index 9284d65..81221f7 100644 --- a/apps/sparo-lib/src/services/ArgvService.ts +++ b/apps/sparo-lib/src/services/ArgvService.ts @@ -25,6 +25,8 @@ export class ArgvService { // --verbose .boolean('verbose') .middleware([this._terminalMiddleware]) + .alias('help', 'h') + .strict() .parseAsync(); } diff --git a/common/changes/sparo/main_2024-03-01-12-30.json b/common/changes/sparo/main_2024-03-01-12-30.json new file mode 100644 index 0000000..b7240a7 --- /dev/null +++ b/common/changes/sparo/main_2024-03-01-12-30.json @@ -0,0 +1,10 @@ +{ + "changes": [ + { + "packageName": "sparo", + "comment": "Add help alias and enable strict mode", + "type": "none" + } + ], + "packageName": "sparo" +} \ No newline at end of file From 082cfb3cebbcb4eaf3d5be4c6b4df8737bff9eec Mon Sep 17 00:00:00 2001 From: qun <68707557+L-Qun@users.noreply.github.com> Date: Fri, 1 Mar 2024 15:15:59 +0000 Subject: [PATCH 2/2] chore: help --- apps/sparo-lib/src/cli/SparoCICommandLine.ts | 5 ++-- apps/sparo-lib/src/cli/SparoCommandLine.ts | 5 ++-- apps/sparo-lib/src/cli/commands/ci-help.ts | 30 -------------------- apps/sparo-lib/src/cli/commands/cmd-list.ts | 5 +--- apps/sparo-lib/src/cli/commands/help.ts | 27 ------------------ 5 files changed, 5 insertions(+), 67 deletions(-) delete mode 100644 apps/sparo-lib/src/cli/commands/ci-help.ts delete mode 100644 apps/sparo-lib/src/cli/commands/help.ts diff --git a/apps/sparo-lib/src/cli/SparoCICommandLine.ts b/apps/sparo-lib/src/cli/SparoCICommandLine.ts index 8b59127..cb0d987 100644 --- a/apps/sparo-lib/src/cli/SparoCICommandLine.ts +++ b/apps/sparo-lib/src/cli/SparoCICommandLine.ts @@ -4,7 +4,6 @@ import { CommandService } from '../services/CommandService'; import { CI_COMMAND_LIST } from './commands/cmd-list'; import { ICommand } from './commands/base'; import { ArgvService } from '../services/ArgvService'; -import { CIHelpCommand } from './commands/ci-help'; import { GitVersionCompatibility } from '../logic/GitVersionCompatibility'; import { TelemetryService } from '../services/TelemetryService'; import { getCommandName } from './commands/util'; @@ -51,8 +50,8 @@ export class SparoCICommandLine { const userInputCmdName: string = argv.getUserCommand(); if (!userInputCmdName || !this._supportedCommand(userInputCmdName)) { - const helpCommand: CIHelpCommand = await getFromContainerAsync(CIHelpCommand); - return helpCommand.handler(); + argv.yargsArgv.showHelp(); + return; } } diff --git a/apps/sparo-lib/src/cli/SparoCommandLine.ts b/apps/sparo-lib/src/cli/SparoCommandLine.ts index a7a80eb..d89695f 100644 --- a/apps/sparo-lib/src/cli/SparoCommandLine.ts +++ b/apps/sparo-lib/src/cli/SparoCommandLine.ts @@ -4,7 +4,6 @@ import { GitService } from '../services/GitService'; import { CommandService } from '../services/CommandService'; import { ArgvService } from '../services/ArgvService'; import { COMMAND_LIST } from './commands/cmd-list'; -import { HelpCommand } from './commands/help'; import { ICommand } from './commands/base'; import { GitVersionCompatibility } from '../logic/GitVersionCompatibility'; import { TelemetryService } from '../services/TelemetryService'; @@ -51,8 +50,8 @@ export class SparoCommandLine { await argv.parseArgvAsync(); const userInputCmdName: string = argv.getUserCommand(); if (!userInputCmdName) { - const helpCommand: HelpCommand = await getFromContainerAsync(HelpCommand); - return helpCommand.handler(); + argv.yargsArgv.showHelp(); + return; } // proxy to gitService diff --git a/apps/sparo-lib/src/cli/commands/ci-help.ts b/apps/sparo-lib/src/cli/commands/ci-help.ts deleted file mode 100644 index 01693b3..0000000 --- a/apps/sparo-lib/src/cli/commands/ci-help.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { Command } from '../../decorator'; -import type { Argv } from 'yargs'; -import type { ICommand } from './base'; - -export interface ICIHelpCommandOptions {} - -@Command() -export class CIHelpCommand implements ICommand { - public cmd: string = 'help'; - public description: string = ''; - - public builder(yargs: Argv): void { - yargs.command( - 'commands', - 'commands', - () => {}, - () => { - console.log('command help'); - } - ); - } - public async handler(): Promise { - console.log(`Sparo CI -usage: sparo-ci COMMAND [OPTIONS] -`); - } - public getHelp(): string { - return ''; - } -} diff --git a/apps/sparo-lib/src/cli/commands/cmd-list.ts b/apps/sparo-lib/src/cli/commands/cmd-list.ts index 61cec54..204292b 100644 --- a/apps/sparo-lib/src/cli/commands/cmd-list.ts +++ b/apps/sparo-lib/src/cli/commands/cmd-list.ts @@ -1,10 +1,8 @@ import { Constructable } from '../../di/types'; import { CloneCommand } from './clone'; -import { HelpCommand } from './help'; import { ListProfilesCommand } from './list-profiles'; import { AutoConfigCommand } from './auto-config'; import { FetchCommand } from './fetch'; -import { CIHelpCommand } from './ci-help'; import { CICheckoutCommand } from './ci-checkout'; import { CICloneCommand } from './ci-clone'; import { CheckoutCommand } from './checkout'; @@ -17,7 +15,6 @@ import { InitProfileCommand } from './init-profile'; // When adding new Sparo subcommands, remember to update this doc page: // https://github.com/tiktok/sparo/blob/main/apps/website/docs/pages/commands/overview.md export const COMMAND_LIST: Constructable[] = [ - HelpCommand, AutoConfigCommand, ListProfilesCommand, InitProfileCommand, @@ -33,4 +30,4 @@ export const COMMAND_LIST: Constructable[] = [ GitPullCommand ]; -export const CI_COMMAND_LIST: Constructable[] = [CICloneCommand, CICheckoutCommand, CIHelpCommand]; +export const CI_COMMAND_LIST: Constructable[] = [CICloneCommand, CICheckoutCommand]; diff --git a/apps/sparo-lib/src/cli/commands/help.ts b/apps/sparo-lib/src/cli/commands/help.ts deleted file mode 100644 index 307fb95..0000000 --- a/apps/sparo-lib/src/cli/commands/help.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { Command } from '../../decorator'; -import type { Argv } from 'yargs'; -import type { ICommand } from './base'; -import { ArgvService } from '../../services/ArgvService'; -import { inject } from 'inversify'; - -export interface IHelpCommandOptions {} - -@Command() -export class HelpCommand implements ICommand { - public cmd: string = 'help'; - public description: string = ''; - - @inject(ArgvService) private _yargs!: ArgvService; - - public builder(yargs: Argv<{}>): void { - yargs.help(false); - } - - public handler = async (): Promise => { - this._yargs.yargsArgv.showHelp(); - }; - - public getHelp(): string { - return ''; - } -}