When defining subcommand properties like alias or brief in the parent commands subcommands export, there is no error shown, when a subcommand does not exist:
src/
+-- app.ts
+-- commands/
| +-- default.ts
| +-- my-command.ts
// src/commands/default.ts
import { SubcommandDefinition } from 'clime'
export const subcommands: SubcommandDefinition[] = [
{
name: 'my-cool-command',
brief: "Isn't it cool?",
}
]
$ node bin/app
USAGE
app <subcommand>
SUBCOMMANDS
my-cool-command - Isn't it cool?
my-command - It's definitely cool!.
$ node bin/app my-cool-command
ERR Unknown subcommand "my-cool-command".
USAGE
app <subcommand>
SUBCOMMANDS
my-cool-command - Isn't it cool?
my-command - It's definitely cool!.
As you can see, there is no such command like my-cool-command but it is displayed because it is defined in default.ts.
My suggestion is to test if the command exists (or at least if one of the files my-cool-command.js or my-cool-command/default.js exist) and to present the user with an error or at least a warning when it does not.
Example:
$ node bin/app
USAGE
app <subcommand>
SUBCOMMANDS
my-command - It's definitely cool!.
WARN Subcommand 'my-cool-command' is defined but does not exist!
Note that the missing subcommand would not be listed as subcommand and a warning would be displayed below the output.
When defining subcommand properties like
aliasorbriefin the parent commandssubcommandsexport, there is no error shown, when a subcommand does not exist:As you can see, there is no such command like
my-cool-commandbut it is displayed because it is defined indefault.ts.My suggestion is to test if the command exists (or at least if one of the files
my-cool-command.jsormy-cool-command/default.jsexist) and to present the user with an error or at least a warning when it does not.Example:
Note that the missing subcommand would not be listed as subcommand and a warning would be displayed below the output.