import { Command } from "https://deno.land/x/cliffy@v0.17.0/mod.ts";
Properties
Methods
Handle error. If throwErrors
is enabled the error will be returned,
otherwise a formatted error message will be printed and Deno.exit(1)
will be called.
Set command arguments:
requiredArg:string [optionalArg: number] [...restArgs:string]
Set default command. The default command is executed when the program was called without any argument and if no action handler is registered.
Get arguments definition. E.g: input-file:string output-file:string
Get base command by name.
Get base environment variable by name.
Get global command by name.
Get global environment variable by name.
Get global option from parent command's by name.
Get parent command from global executed command. Be sure, to call this method only inside an action handler. Unless this or any child command was executed, this method returns always undefined.
Get short command description. This is the first line of the description.
Checks whether the command has a sub-command with given name or not.
Checks whether the command has an environment variable with given name or not.
Checks whether the command has an option with given name or not.
Parse command line arguments and execute matched command.
Enable stop early. If enabled, all arguments starting from the first non option argument will be passed as arguments with type string to the command action handler.
For example:
command --debug-level warning server --port 80
Will result in:
- options: {debugLevel: 'warning'}
- args: ['server', '--port', '80']
Throw validation error's instead of calling Deno.exit()
to handle
validation error's manually.
A validation error is thrown when the command is wrongly used by the user. For example: If the user passes some invalid options or arguments to the command.
This has no effect for parent commands. Only for the command on which this method was called and all child commands.
Example:
try {
cmd.parse();
} catch(error) {
if (error instanceof ValidationError) {
cmd.showHelp();
Deno.exit(1);
}
throw error;
}
Disable parsing arguments. If enabled the raw arguments will be passed to the action handler. This has no effect for parent or child commands. Only for the command on which this method was called.