mirror of
https://github.com/tiktok/sparo.git
synced 2024-11-14 19:35:12 -05:00
Merge pull request #37 from L-Qun/main
chore: add help alias and enable strict mode
This commit is contained in:
commit
ea8ab4cb68
7 changed files with 17 additions and 62 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 '';
|
||||
}
|
||||
}
|
|
@ -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];
|
||||
|
|
|
@ -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 '';
|
||||
}
|
||||
}
|
|
@ -25,6 +25,8 @@ export class ArgvService {
|
|||
// --verbose
|
||||
.boolean('verbose')
|
||||
.middleware([this._terminalMiddleware])
|
||||
.alias('help', 'h')
|
||||
.strict()
|
||||
.parseAsync();
|
||||
}
|
||||
|
||||
|
|
10
common/changes/sparo/main_2024-03-01-12-30.json
Normal file
10
common/changes/sparo/main_2024-03-01-12-30.json
Normal file
|
@ -0,0 +1,10 @@
|
|||
{
|
||||
"changes": [
|
||||
{
|
||||
"packageName": "sparo",
|
||||
"comment": "Add help alias and enable strict mode",
|
||||
"type": "none"
|
||||
}
|
||||
],
|
||||
"packageName": "sparo"
|
||||
}
|
Loading…
Reference in a new issue