So far we have seen commands defined by a single word, but it is also possible to define commands that require more than one command word to invoke.
For example, you might want to have a range of commands that are grouped logically - they might be commands to manage the same entity:
client create
- Add a new clientclient delete
- Delete an existing clientclient update
- Update an existing clientclient show
- Show the details for an existing clientThis way you could have similar sets of commands for handling other entities:
user create
- Add a new useruser delete
- Delete an existing useruser update
- Update an existing useruser show
- Show the details for an existing userAlternatively you might want to qualify operations:
create client
- Add a new clientcreate user
- Add a new userdelete client
- Delete an existing clientdelete user
- Delete an existing userupdate client
- Update an existing clientupdate user
- Update an existing usershow client
- Show the details for an existing clientshow user
- Show the details for an existing userThe toolkit supports this requirement through “command keywords”. For example:
Here the command is called “add” and has a “user” keyword. Keywords precede the command name, so to invoke this command, you would need to specify “user add”.
You can also supply documentation for keywords, which will be used to generate the help text by adding a description to the keyword definition:
[Keyword("user", "User operations")]
It will be usual for the keyword to be specified on multiple commands, so it is not mandatory to supply a description, and the help system will check all of the commands specifying the keyword for text. Only the first version of the text found will be used, so in general it is better to specify the keyword’s description only once in the application.
We’ve seen the “standard” style of help command in
Here there is only a single topic, which would not allow us to request help on commands with keywords. i.e. help user add
would be invalid, because only one positional parameter is allowed.
To define a multi-word help command, we need to change the definition a little:
Above you will notice that the “Topic” property is now a List<string>
instead of a string
, which will allow topics with multiple words to be requested.
If you define a set of commands with the same keyword, the keyword will start to appear in help output:
Here you can see four “commands” - but “client” and “user” are in fact keywords. If we were to specify “client” as a topic, the help formatting would reflect just the commands with the “client” prefix:
Specifying all of the keywords for a command displays the usual help text for the command. For example, if we specified “client add” as the help topic: