parentScopedFlags returns inherited flags that originate from a non-root parent command. These are promoted into the FLAGS section so they're immediately visible on leaf commands.
(cmd *cobra.Command)
| 254 | // parent command. These are promoted into the FLAGS section so they're |
| 255 | // immediately visible on leaf commands. |
| 256 | func parentScopedFlags(cmd *cobra.Command) *pflag.FlagSet { |
| 257 | root := cmd.Root() |
| 258 | ps := pflag.NewFlagSet("parent-scoped", pflag.ContinueOnError) |
| 259 | cmd.InheritedFlags().VisitAll(func(f *pflag.Flag) { |
| 260 | rootFlag := root.PersistentFlags().Lookup(f.Name) |
| 261 | if rootFlag != nil && rootFlag == f { |
| 262 | return // root-level — stays in INHERITED FLAGS |
| 263 | } |
| 264 | ps.AddFlag(f) |
| 265 | }) |
| 266 | return ps |
| 267 | } |
| 268 | |
| 269 | // filterInheritedFlags returns formatted flag usages for INHERITED FLAGS, |
| 270 | // containing only the curated subset of root-level globals. |