* Move default command validation to build
Move the validation of default commands - checking if a node has
multiple default commands or a default command has children - to the
build phase rather than tracing. These errors are with the structure of
the CLI ast and are detectable before parsing the command line.
Add a couple of tests for some of the default command error cases.
* Disallow positional args on a default command
Do not allow a default command to have positional arguments. The current
check is only for branching args, but the error message implies that
positional args are not allowed either. So add a check for positional
args too, and add a test case for it.
This is breaking change to the API but is unlikely to have ill-effect as
positional args on a default command cannot be used without explicitly
naming the command (i.e. not using it as a default).
* Allow default commands with cmds/args/flags
Allow default commands to have sub-commands, args and flags when tagged
with `default:"withargs"`. This makes specifying the name of the
command on the CLI completely optional as long as the args to that
command are not ambiguous with other commands.
This new tag tells the parser to stop processing flags after the
positional argument is encountered.
This is particularly useful for subcommands that forward their arguments
to an external program, and makes it possible to implement commands
like `kubectl exec` or `docker run`.
Fixes#80.
Will automatically set a boolean Struct field to false if the flag starts with `--no-`, even when the default is `true`.
For example:
```
type Cmd struct {
Output bool `default:"true"`
}
```
Calling
```
command
```
Will set `Output` to `true`, but
```
command --no-output
```
Will set `Output` to `false`.
This was breaking UsageOnMissing() when combined with validation of
positional arguments, in that it was allowing positional arguments to be
omitted. It also broke UsageOnMissing() somehow so that it did not work.
Refactors usageOnMissing option to not run parent commands after
printing usage when a child node is missing.
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
Adds an UsageOnMissing option which configures Kong to omit errors and
display usage when a command is invalid due to a missing argument. This
can be useful if a user wishes for the top-level command to print usage
when no args are supplied, or if they would prefer child commands which
have their own subcommands to print usage specific to that command.
Signed-off-by: hasheddan <georgedanielmangum@gmail.com>
This is useful for situations where the initialisation of some object
should be deferred, eg. when there are distinct "setup" and "use" phases
to a tools lifecycle.