-
Notifications
You must be signed in to change notification settings - Fork 3
Home
These are the scenarios that we would like to see in an optimal command line tool. Ideally, we'd like to turn this document into runnable tests.
The following examples are things that it should support, but we don't know yet what the ruby code to generate the parser is yet. We'll get to that eventually.
Come join us by commenting on these scenarios, and perhaps adding your own.
Given a shell program using the parser called optimal
It should be able to parse options with arguments.
optimal --foo=bar
optimal --foo bar
optimal -f bar
optimal -fbar
boolean options do not require an argument, but one can be provided in its long form with the =
sign. The following are all equivalent
optimal --bool
optimal -b
for i in y Y yes YES t T true TRUE; do
opitmal --bool=i
done;
Options can be concatenated chained to apply many at once. Note, when doing this only the last option can receive an argument.
optimal --foo --monkey --bar=baz
optimal -f -m -b baz
optimal -fmb baz
optimal -fbm baz # Error! baz is assigned to monkey.
Options may, at their discretion, take multiple arguments
optimal --multi one two three (an example of this in the wild is the -b in git checkout)
Arguments without a dash and are not arguments to options are commands. Commands typically execute some involved action. Commands get the choice of intercepting any options after the command is listed. If the command does not handle the option, it will pass it to the parent handler.
optimal start # OK: start optimal
optimal --verbose start # start optimal loudly
optimal start --verbose # start ignores --verbose, passing it up to optimal
optimal --verbose start --port 8080 # OK: start can intercept the --port option
optimal start --verbose --port 8080 # OK: start intercepts --port but passes --verbose up
optimal --verbose --port 8080 start # Error: optimal doesn't understand --port!
Commands themselves can take more than one argument
optimal start several things