diff options
Diffstat (limited to 'command/flag.go')
| -rw-r--r-- | command/flag.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/command/flag.go b/command/flag.go index 8e890a1a..cb85a648 100644 --- a/command/flag.go +++ b/command/flag.go @@ -44,6 +44,26 @@ func (v BoolFlag) Define(b *strings.Builder, set *flag.FlagSet, p any, name, usa b.WriteString(" [" + prettyFlag(name) + "]") } +// RepeatableFlag implements an ordered, repeatable string flag. +type RepeatableFlag []string + +func (r *RepeatableFlag) String() string { + if r == nil { + return "<nil>" + } + return strings.Join(*r, " ") +} + +func (r *RepeatableFlag) Set(v string) error { + *r = append(*r, v) + return nil +} + +func (r *RepeatableFlag) Define(b *strings.Builder, set *flag.FlagSet, _ any, name, usage string) { + set.Var(r, name, usage) + b.WriteString(" [" + prettyFlag(name) + " <value>]") +} + // this has no effect on parse outcome func prettyFlag(name string) string { switch len(name) { |
