Add "Hidden" option to comamnds and options
diff --git a/command.go b/command.go
index 13332ae..f8579d2 100644
--- a/command.go
+++ b/command.go
@@ -23,6 +23,9 @@
// Whether positional arguments are required
ArgsRequired bool
+ // If true, the option is not displayed in the help output
+ Hidden bool
+
commands []*Command
hasBuiltinHelpGroup bool
args []*Arg
diff --git a/command_private.go b/command_private.go
index 5d30a8a..2107ee0 100644
--- a/command_private.go
+++ b/command_private.go
@@ -201,9 +201,15 @@
c[i], c[j] = c[j], c[i]
}
+// FIXME: maybe call this sortedVisibleCommands ?
func (c *Command) sortedCommands() []*Command {
- ret := make(commandList, len(c.commands))
- copy(ret, c.commands)
+ ret := make(commandList, 0, len(c.commands))
+
+ for _, e := range c.commands {
+ if !e.Hidden {
+ ret = append(ret, e)
+ }
+ }
sort.Sort(ret)
return []*Command(ret)
diff --git a/flags.go b/flags.go
index 37d331d..7bdcdb4 100644
--- a/flags.go
+++ b/flags.go
@@ -104,6 +104,7 @@
slices and maps (optional)
value-name: the name of the argument value (to be shown in the help)
(optional)
+ hidden: the option is not visible in the help output
base: a base (radix) used to convert strings to integer values, the
default base is 10 (i.e. decimal) (optional)
diff --git a/group_private.go b/group_private.go
index 15251ce..569c81b 100644
--- a/group_private.go
+++ b/group_private.go
@@ -131,6 +131,7 @@
optional := (mtag.Get("optional") != "")
required := (mtag.Get("required") != "")
+ hidden := (mtag.Get("hidden") != "")
option := &Option{
Description: description,
@@ -144,6 +145,7 @@
Required: required,
ValueName: valueName,
DefaultMask: defaultMask,
+ Hidden: hidden,
group: g,
diff --git a/help.go b/help.go
index e26fcd0..88c4b5f 100644
--- a/help.go
+++ b/help.go
@@ -108,6 +108,10 @@
prefix += 4
}
+ if option.Hidden {
+ return
+ }
+
line.WriteString(strings.Repeat(" ", prefix))
if option.ShortName != 0 {
diff --git a/option.go b/option.go
index 29e702c..00fb461 100644
--- a/option.go
+++ b/option.go
@@ -51,6 +51,9 @@
// error.
Required bool
+ // If true, the option is not displayed in the help output
+ Hidden bool
+
// A name for the value of an option shown in the Help as --flag [ValueName]
ValueName string