Command Annotations
TODO Describe @Command, @Option, @Argument, and @RemainingArgs
Command Invocation
Escaping
Commands are invoked on the server using a command line style interface in which parameters are passed to the command being executing as option or argument token separated by one or more whitespace characters. The rules for escaping are straightforward:
- To pass a string with whitespace as a single token it must be wrapped in quotes for example "My Text" so that the parser can tell that it is one argument rather than two arguments.
- Quotes within a quoted string must be escaped, so to represent an argument "My Text" with the surrounding quotes being passed in the parameter escaped quotes must be used: "\"My Text\""
- Because the command parser treats any token starting with '-' as an option negative leading dash characters must be escaped by prefixing them with a '\', for example \-3.1456.
The following simple command serves to demonstrate when escaping is necessary. This command prints a given line to either System.err or System.out:
Passing A String with Spaces
The above will result in the following being printed to System.out in the App:
My String
Passing A String with Quotes
Note that below we escape the quote characters within the quoted string:
All of the above will result in the following being printed to System.error in the App (with the quotes preserved). Not that in the java case that the extra escapes are needed to escape the '\' character.
ERROR [0]: "My Error"
Passing Argument Starting With A Dash
Note that below we escape the quote characters within the quoted string:
All of the above will result in the following being printed to System.error in the App (with the quotes preserved)
ERROR[-10]: --BAD_TIMES--
Supported Types for Options, Arguments And Return values:
The following types are returned when describing the command usage. In Json they are represented as the name from the enumeration below. The expectation is that tools will use this options in forms.
Examples
A Fully Annotated Command
Usage as Printed By SrvMonUtil
testCommand A command that exercises all of the invocation APIs Usage: testCommand -b -c -n -i -l -f -d -s -m -e <aByteArgument> <aCharArgument> <aShortArgument> <aIntArgument> <aLongArgument> <aFloatArgument> <aDoubleArgument> <aStringArgument> <aCurrencyArgument> <aEnumArgument> <-b|--byteOption> <1|0,> Tests a byte Option default='0' <-c|--charOption> <a,|b|c> Tests a char Option default='b' <-n|--shortOption> <300|399,> Tests a short Option default='399' <-i|--intOption> <200000|20000,> Tests a int Option default='200000' <-l|--longOption> <100000000,|2000000000> Tests a long Option default='100000000' <-f|--floatOption> <0.0,|-2.0> Tests a float Option default='0.0' <-d|--doubleOption> <0.0,|1.2> Tests a double Option default='1.2' <-s|--stringOption> <Bar|Foo,> Tests a String Option default='Foo' <-m|--currencyOption> <JPY|USD,> Tests a Currency Option default='JPY' <-e|--enumOption> Tests a Enum Option default='PrettyPrint' [aByteArgument: <1|0,> Tests a byte Arguement default='0'] [aCharArgument: <a,|b|c> Tests a char Arguement default='a'] [aShortArgument: <300|399,> Tests a short Arguement default='300'] [aIntArgument: <200000|20000,> Tests a int Arguement default='200000'] [aLongArgument: <100000000,|2000000000> Tests a long Arguement default='100000000'] [aFloatArgument: <0.0,|-2.01> Tests a float Arguement default='-2.01'] [aDoubleArgument: <0.0,|1.2> Tests a double Arguement default='0.0'] [aStringArgument: <Bar|Foo,> Tests a String Arguement default='Foo'] [aCurrencyArgument: <JPY|USD,> Tests a Currency Arguement default='USD'] [aEnumArgument: Tests a Enum Arguement default='Minimal']
Json Command Description: