Skip to content

Commit

Permalink
Merge pull request #105 from marco-m/document-subcommand-fail-early
Browse files Browse the repository at this point in the history
README: how to terminate a program when no subcommands are specified
  • Loading branch information
alexflint authored Jan 23, 2020
2 parents f5d3733 + 5943b1a commit 7e2466d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 7e2466d

Please sign in to comment.