Merge remote-tracking branch 'mvo5/master'
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 c0d6ce3..0a77ab2 100644
--- a/command_private.go
+++ b/command_private.go
@@ -235,9 +235,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 641fe01..6656848 100644
--- a/flags.go
+++ b/flags.go
@@ -108,6 +108,7 @@
(optional)
choice: limits the values for an option to a set of values.
This tag can be specified mltiple times (optional)
+ hidden: the option is not visible in the help or man page.
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 e2b1d9c..96c3619 100644
--- a/group_private.go
+++ b/group_private.go
@@ -132,6 +132,7 @@
optional := (mtag.Get("optional") != "")
required := (mtag.Get("required") != "")
choices := mtag.GetMany("choice")
+ hidden := (mtag.Get("hidden") != "")
option := &Option{
Description: description,
@@ -146,6 +147,7 @@
ValueName: valueName,
DefaultMask: defaultMask,
Choices: choices,
+ Hidden: hidden,
group: g,
diff --git a/help.go b/help.go
index 8035ef5..fab5450 100644
--- a/help.go
+++ b/help.go
@@ -165,6 +165,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 068ea32..afad7e4 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