feat: show help text

This commit is contained in:
Cheng Liu 2024-02-27 16:02:18 -08:00
parent fe6e9ac69b
commit b1d04a9780
No known key found for this signature in database
GPG key ID: EEC8452F7DB85CD6
8 changed files with 37 additions and 26 deletions

View file

@ -56,9 +56,17 @@ export class CheckoutCommand implements ICommand<ICheckoutCommandOptions> {
.positional('start-point', {
type: 'string'
})
.boolean('b')
.string('branch')
.string('startPoint')
.option('b', {
type: 'boolean',
description: 'Create a new branch and start it at <start-point>'
})
.option('B', {
type: 'boolean',
description:
'Create a new branch and start it at <start-point>; if it already exists, reset it to <start-point>'
})
.array('profile')
.default('profile', [])
.array('add-profile')

View file

@ -12,7 +12,9 @@ export class GitCheckoutCommand implements ICommand<{}> {
public description: string = 'original git checkout command';
@inject(GitService) private _gitService!: GitService;
public builder(yargs: Argv<{}>): void {}
public builder(yargs: Argv<{}>): void {
yargs.help(false);
}
public handler = async (args: ArgumentsCamelCase<{}>, terminalService: TerminalService): Promise<void> => {
const { _gitService: gitService } = this;

View file

@ -12,7 +12,9 @@ export class GitCloneCommand implements ICommand<{}> {
public description: string = 'original git clone command';
@inject(GitService) private _gitService!: GitService;
public builder(yargs: Argv<{}>): void {}
public builder(yargs: Argv<{}>): void {
yargs.help(false);
}
public handler = async (args: ArgumentsCamelCase<{}>, terminalService: TerminalService): Promise<void> => {
const { _gitService: gitService } = this;

View file

@ -13,7 +13,9 @@ export class GitFetchCommand implements ICommand<{}> {
@inject(GitService) public _gitService!: GitService;
public builder(yargs: Argv<{}>): void {}
public builder(yargs: Argv<{}>): void {
yargs.help(false);
}
public handler = async (args: ArgumentsCamelCase<{}>, terminalService: TerminalService): Promise<void> => {
const { _gitService: gitService } = this;

View file

@ -11,7 +11,11 @@ export class GitPullCommand implements ICommand<{}> {
public cmd: string = 'git-pull';
public description: string = 'original git pull command';
@inject(GitService) public _gitService!: GitService;
public builder(yargs: Argv<{}>): void {}
public builder(yargs: Argv<{}>): void {
yargs.help(false);
}
public handler = async (args: ArgumentsCamelCase<{}>, terminalService: TerminalService): Promise<void> => {
const { _gitService: gitService } = this;
const { terminal } = terminalService;

View file

@ -1,5 +1,5 @@
import { Command } from '../../decorator';
import { Argv } from 'yargs';
import type { Argv } from 'yargs';
import type { ICommand } from './base';
export interface IHelpCommandOptions {}
@ -8,22 +8,14 @@ export interface IHelpCommandOptions {}
export class HelpCommand implements ICommand<IHelpCommandOptions> {
public cmd: string = 'help';
public description: string = '';
private _yargs: Argv<IHelpCommandOptions> | undefined;
public builder(yargs: Argv<IHelpCommandOptions>): void {
yargs.command(
'commands',
'commands',
() => {},
() => {
console.log('command help');
}
);
}
public async handler(): Promise<void> {
console.log(`Sparo
usage: sparo COMMAND [OPTIONS]
`);
}
public builder = (yargs: Argv<IHelpCommandOptions>): void => {
this._yargs = yargs;
};
public handler = async (): Promise<void> => {
this._yargs?.showHelp();
};
public getHelp(): string {
return '';
}

View file

@ -18,14 +18,16 @@ export class InitProfileCommand implements ICommand<IInitProjectCommandOptions>
public cmd: string = 'init-profile';
public description: string = 'Initialize a new profile.';
// template section name --> whether it should be commented out
private _commentedBySectionName: Map<string, boolean> = new Map<string, boolean>();
@inject(SparoProfileService) private _sparoProfileService!: SparoProfileService;
@inject(TerminalService) private _terminalService!: TerminalService;
public builder(yargs: Argv<IInitProjectCommandOptions>): void {
yargs.string('profile').demandOption(['profile']);
yargs
.option('profile', {
type: 'string',
description: 'The name of the profile to initialize.'
})
.demandOption(['profile']);
}
public handler = async (

View file

@ -20,7 +20,6 @@ export class ArgvService {
public async parseArgvAsync(): Promise<void> {
this._parsed = await this.yargsArgv
.help(false)
// --debug
.boolean('debug')
// --verbose