diff options
| author | Alex Flint <[email protected]> | 2020-01-23 11:08:28 -0800 |
|---|---|---|
| committer | GitHub <[email protected]> | 2020-01-23 11:08:28 -0800 |
| commit | 7e2466d70798086a87f82713cfba49dae0af494f (patch) | |
| tree | d673620d870f530956e76a4cc8dec1cacd8a4d65 | |
| parent | f5d3733c0a632d810fb2f742a1b9caaef85374d9 (diff) | |
| parent | 5943b1ad42eb1faeef8363f7c0078888d0589f7f (diff) | |
Merge pull request #105 from marco-m/document-subcommand-fail-early
README: how to terminate a program when no subcommands are specified
| -rw-r--r-- | README.md | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -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 |
