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
  • Loading branch information
niamster committed Jan 6, 2024
1 parent 637ba7b commit 5105640
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 @@ -1653,6 +1655,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 @@ -1666,6 +1669,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 @@ -1693,6 +1697,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 @@ -1718,6 +1723,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 5105640

Please sign in to comment.