Skip to content

Commit

Permalink
Merge pull request #207 from rsteube/command-persistent
Browse files Browse the repository at this point in the history
command: support persistent flag
  • Loading branch information
rsteube authored Sep 1, 2023
2 parents 7817233 + 31760bb commit c4b9bff
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
15 changes: 12 additions & 3 deletions pkg/command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,17 @@ type Command struct {
}

func (c *Command) AddFlag(f Flag) {
if c.Flags == nil {
c.Flags = make(map[string]string)
switch {
case f.Persistent:
if c.PersistentFlags == nil {
c.PersistentFlags = make(map[string]string)
}
c.PersistentFlags[f.format()] = f.Usage

default:
if c.Flags == nil {
c.Flags = make(map[string]string)
}
c.Flags[f.format()] = f.Usage
}
c.Flags[f.format()] = f.Usage
}
1 change: 1 addition & 0 deletions pkg/command/flag.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ type Flag struct {
Value bool
Hidden bool
Required bool
Persistent bool
}

func (f Flag) format() string {
Expand Down

0 comments on commit c4b9bff

Please sign in to comment.