Skip to content

Commit

Permalink
flags: clarify documentation that LocalFlags related function do not …
Browse files Browse the repository at this point in the history
…modify the state (#2064)
  • Loading branch information
niamster authored Jan 6, 2024
1 parent 0dec88e commit 4fb0a66
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions command.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,10 @@ type Command struct {
// pflags contains persistent flags.
pflags *flag.FlagSet
// lflags contains local flags.
// This field does not represent internal state, it's used as a cache to optimise LocalFlags function call
lflags *flag.FlagSet
// iflags contains inherited flags.
// This field does not represent internal state, it's used as a cache to optimise InheritedFlags function call
iflags *flag.FlagSet
// parentsPflags is all persistent flags of cmd's parents.
parentsPflags *flag.FlagSet
Expand Down Expand Up @@ -1659,6 +1661,7 @@ func (c *Command) Flags() *flag.FlagSet {
}

// LocalNonPersistentFlags are flags specific to this command which will NOT persist to subcommands.
// This function does not modify the flags of the current command, it's purpose is to return the current state.
func (c *Command) LocalNonPersistentFlags() *flag.FlagSet {
persistentFlags := c.PersistentFlags()

Expand All @@ -1672,6 +1675,7 @@ func (c *Command) LocalNonPersistentFlags() *flag.FlagSet {
}

// LocalFlags returns the local FlagSet specifically set in the current command.
// This function does not modify the flags of the current command, it's purpose is to return the current state.
func (c *Command) LocalFlags() *flag.FlagSet {
c.mergePersistentFlags()

Expand Down Expand Up @@ -1699,6 +1703,7 @@ func (c *Command) LocalFlags() *flag.FlagSet {
}

// InheritedFlags returns all flags which were inherited from parent commands.
// This function does not modify the flags of the current command, it's purpose is to return the current state.
func (c *Command) InheritedFlags() *flag.FlagSet {
c.mergePersistentFlags()

Expand All @@ -1724,6 +1729,7 @@ func (c *Command) InheritedFlags() *flag.FlagSet {
}

// NonInheritedFlags returns all flags which were not inherited from parent commands.
// This function does not modify the flags of the current command, it's purpose is to return the current state.
func (c *Command) NonInheritedFlags() *flag.FlagSet {
return c.LocalFlags()
}
Expand Down

0 comments on commit 4fb0a66

Please sign in to comment.