Skip to content

Commit

Permalink
Merge pull request #27 from tiktok/feat-help
Browse files Browse the repository at this point in the history
feat: show help text
  • Loading branch information
chengcyber authored Feb 28, 2024
2 parents aeda51a + 33ed518 commit f0a5e86
Show file tree
Hide file tree
Showing 9 changed files with 47 additions and 26 deletions.
10 changes: 9 additions & 1 deletion apps/sparo-lib/src/cli/commands/checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
4 changes: 3 additions & 1 deletion apps/sparo-lib/src/cli/commands/git-checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion apps/sparo-lib/src/cli/commands/git-clone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 3 additions & 1 deletion apps/sparo-lib/src/cli/commands/git-fetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion apps/sparo-lib/src/cli/commands/git-pull.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 8 additions & 16 deletions apps/sparo-lib/src/cli/commands/help.ts
Original file line number Diff line number Diff line change
@@ -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 {}
Expand All @@ -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 '';
}
Expand Down
10 changes: 6 additions & 4 deletions apps/sparo-lib/src/cli/commands/init-profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
1 change: 0 additions & 1 deletion apps/sparo-lib/src/services/ArgvService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ export class ArgvService {

public async parseArgvAsync(): Promise<void> {
this._parsed = await this.yargsArgv
.help(false)
// --debug
.boolean('debug')
// --verbose
Expand Down
10 changes: 10 additions & 0 deletions common/changes/sparo/feat-help_2024-02-28-00-03.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "sparo",
"comment": "--help and help shows basic help text",
"type": "none"
}
],
"packageName": "sparo"
}

0 comments on commit f0a5e86

Please sign in to comment.