README: how to terminate a program when no subcommands are specified

Fixes #103
This commit is contained in:
Marco Molteni 2020-01-23 18:16:28 +01:00
parent ced05bfe8a
commit 5943b1ad42
1 changed files with 11 additions and 0 deletions

View File

@ -442,6 +442,17 @@ Some additional rules apply when working with subcommands:
* The `subcommand` tag can only be used with fields that are pointers to structs
* Any struct that contains a subcommand must not contain any positionals
This package allows to have a program that accepts subcommands, but also does something else
when no subcommands are specified.
If on the other hand you want the program to terminate when no subcommands are specified,
the recommended way is:
```go
p := arg.MustParse(&args)
if p.Subcommand() == nil {
p.Fail("missing subcommand")
}
```
### API Documentation