summaryrefslogtreecommitdiff
path: root/README.md
diff options
context:
space:
mode:
authorMarco Molteni <[email protected]>2020-01-23 18:16:28 +0100
committerMarco Molteni <[email protected]>2020-01-23 18:16:28 +0100
commit5943b1ad42eb1faeef8363f7c0078888d0589f7f (patch)
tree1b1c43d7870f10032f7792c23f6c1a77b4b991eb /README.md
parentced05bfe8a0f966d6ed09af656f5410bc5f4ed7c (diff)
README: how to terminate a program when no subcommands are specified
Fixes #103
Diffstat (limited to 'README.md')
-rw-r--r--README.md11
1 files changed, 11 insertions, 0 deletions
diff --git a/README.md b/README.md
index 037d8d9..3a77953 100644
--- a/README.md
+++ b/README.md
@@ -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