Merge pull request #37 from L-Qun/main

chore: add help alias and enable strict mode
This commit is contained in:
Cheng Liu 2024-03-01 12:15:15 -08:00 committed by GitHub
commit ea8ab4cb68
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 17 additions and 62 deletions

View file

@ -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;
}
}

View file

@ -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

View file

@ -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<ICIHelpCommandOptions> {
public cmd: string = 'help';
public description: string = '';
public builder(yargs: Argv<ICIHelpCommandOptions>): void {
yargs.command(
'commands',
'commands',
() => {},
() => {
console.log('command help');
}
);
}
public async handler(): Promise<void> {
console.log(`Sparo CI
usage: sparo-ci COMMAND [OPTIONS]
`);
}
public getHelp(): string {
return '';
}
}

View file

@ -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];

View file

@ -1,22 +0,0 @@
import { Command } from '../../decorator';
import type { Argv } from 'yargs';
import type { ICommand } from './base';
export interface IHelpCommandOptions {}
@Command()
export class HelpCommand implements ICommand<IHelpCommandOptions> {
public cmd: string = 'help';
public description: string = '';
private _yargs: Argv<IHelpCommandOptions> | undefined;
public builder = (yargs: Argv<IHelpCommandOptions>): void => {
this._yargs = yargs;
};
public handler = async (): Promise<void> => {
this._yargs?.showHelp();
};
public getHelp(): string {
return '';
}
}

View file

@ -25,6 +25,8 @@ export class ArgvService {
// --verbose
.boolean('verbose')
.middleware([this._terminalMiddleware])
.alias('help', 'h')
.strict()
.parseAsync();
}

View file

@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "sparo",
"comment": "Add help alias and enable strict mode",
"type": "none"
}
],
"packageName": "sparo"
}