-
-
Notifications
You must be signed in to change notification settings - Fork 14
Command Structure
All built-in RTM CLI commands are automatically parsed from the files in the /src/cmd/
directory in the source code, where each file corresponds to a single command.
Additionally, commands can be added to RTM CLI as a plugin. A plugin can be as simple as a single JavaScript file or a full Node module that exports multiple commands. See the example RTM CLI plugin for an example plugin that provides two commands.
Each command is an Object that has a number of properties describing the command.
At a minimum, the command must contain the following properties:
Property | Type | Description |
---|---|---|
command | string | The command definition that will be parsed by commander |
description | string | Command description that is displayed in the help output |
action | function | This is the function that will be executed when the command is called |
This is a string that will be parsed by commander into the command name and arguments.
No arguments:
test
A single required argument:
test <index>
A single optional argument:
test [index]
A single optional argument as a list:
test [indices...]
A required argument followed by an optional list:
test <index> [tags...]
An error will be displayed when a required argument is not supplied by the user.
Note: Since commander does not parse a quote-enclosed string as a single argument, any multi-word arguments will have to be given as a list argument (only one list argument can be used and it must be the last argument).
This should be a short and concise description of the command and will be displayed with the list of commands in the --help
usage information.
This is the function that is called when the command is executed. It will be given two arguments:
-
args - an array of arguments passed to the command from the user
-
env - the Commander environment, which contains additional command and argument information
Additional properties can be exported as well:
Property | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
alias | string | A single word that is used as an alias for the command | |||||||||
options | Object[] |
Provide one or more options that are only used by this command. This property is an
Array of Objects with the following properties:
env object (as properties of env with the keys set to the long-name of the option). Flag options will be set to true when provided and options with arguments will have the argument value set as the object property value. Ex: rtm test --flag --start mon will have the properties set as: env.flag = true and env.start = mon
|
|||||||||
disableLogin | boolean | Set this property to true to disable the automatic login check that is typically
run before the start of each command. Normally, if there is no stored user information the RTM login
procedure is started before a command is run. This will disable that check. |