func usageFunc(cmd *cobra.Command) error { subCommands := getSubCommands(cmd) tabOut := getTabOutWithWriter(os.Stdout) commandUsageTemplate.Execute(tabOut, struct { Cmd *cobra.Command LocalFlags string GlobalFlags string SubCommands []*cobra.Command Version string }{ cmd, rktFlagUsages(cmd.LocalFlags()), rktFlagUsages(cmd.InheritedFlags()), subCommands, version.Version, }) tabOut.Flush() return nil }
func localFlags(cmd *cobra.Command) *flag.FlagSet { fs := &flag.FlagSet{} if cmd.HasParent() { cmd.LocalFlags().VisitAll(func(f *flag.Flag) { if f.Name != "help" { fs.AddFlag(f) } }) } else { cmd.LocalFlags().VisitAll(func(f *flag.Flag) { if cmd.PersistentFlags().Lookup(f.Name) == nil { fs.AddFlag(f) } }) } return sansAdditionalFlags(fs) }
func setFromFlag(cmd *cobra.Command, flag string, value *string) { if flag := cmd.LocalFlags().Lookup(flag); flag.Changed { *value = flag.Value.String() } }