diff --git a/cli.ts b/cli.ts index f850b7d7..01f0cb19 100644 --- a/cli.ts +++ b/cli.ts @@ -20,14 +20,6 @@ const args = process.argv; const config = await new ConfigManager({}).getConfig(); const cliBuilder = new CliBuilder([ - new CliCommand( - ["help"], - [], - () => { - cliBuilder.displayHelp(); - }, - "Shows help for the CLI" - ), new CliCommand<{ username: string; password: string; diff --git a/packages/cli-parser/index.ts b/packages/cli-parser/index.ts index 126a90ae..4554f096 100644 --- a/packages/cli-parser/index.ts +++ b/packages/cli-parser/index.ts @@ -106,12 +106,28 @@ export class CliBuilder { */ async processArgs(args: string[]) { const revelantArgs = this.getRelevantArgs(args); + + // Handle "-h", "--help" and "help" commands as special cases + if (revelantArgs.length === 1) { + if (["-h", "--help", "help"].includes(revelantArgs[0])) { + this.displayHelp(); + return; + } + } + // Find revelant command // Search for a command with as many categories matching args as possible const matchingCommands = this.commands.filter(command => startsWithArray(revelantArgs, command.categories) ); + if (matchingCommands.length === 0) { + console.log( + `Invalid command "${revelantArgs.join(" ")}". Please use the ${chalk.bold("help")} command to see a list of commands` + ); + return 0; + } + // Get command with largest category size const command = matchingCommands.reduce((prev, current) => prev.categories.length > current.categories.length ? prev : current