aboutsummaryrefslogtreecommitdiff
path: root/flag.go
diff options
context:
space:
mode:
authorJohn Schnake <[email protected]>2016-04-11 10:43:53 -0500
committerJohn Schnake <[email protected]>2016-04-11 14:19:27 -0500
commitb36bf8b7f77c3eff847e3616cfdeb9b88538453f (patch)
treedb352a6007d2989420eaf525fb1f885e2b3c6982 /flag.go
parent1f296710f879815ad9e6d39d947c828c3e4b4c3d (diff)
Add simple method to see if a flagset has available flags
With the hidden and deprecated fields, it is useful to be able to ask if a flagset has any non-hdden, non-deprecated flags. One example of this is to aid in writing help templates.
Diffstat (limited to 'flag.go')
-rw-r--r--flag.go11
1 files changed, 11 insertions, 0 deletions
diff --git a/flag.go b/flag.go
index deac3af..bb03cfc 100644
--- a/flag.go
+++ b/flag.go
@@ -242,6 +242,17 @@ func (f *FlagSet) HasFlags() bool {
return len(f.formal) > 0
}
+// HasAvailableFlags returns a bool to indicate if the FlagSet has any flags
+// definied that are not hidden or deprecated.
+func (f *FlagSet) HasAvailableFlags() bool {
+ for _, flag := range f.formal {
+ if !flag.Hidden && len(flag.Deprecated) == 0 {
+ return true
+ }
+ }
+ return false
+}
+
// VisitAll visits the command-line flags in lexicographical order, calling
// fn for each. It visits all flags, even those not set.
func VisitAll(fn func(*Flag)) {