func UseOptionsTemplates(cmd *cobra.Command) { cmd.SetHelpTemplate(OptionsHelpTemplate()) templater := &templater{ UsageTemplate: OptionsUsageTemplate(), } cmd.SetUsageFunc(templater.UsageFunc()) }
// SetupRootCommand sets default usage, help, and error handling for the // root command. func SetupRootCommand(rootCmd *cobra.Command) { rootCmd.SetUsageTemplate(usageTemplate) rootCmd.SetHelpTemplate(helpTemplate) rootCmd.SetFlagErrorFunc(FlagErrorFunc) rootCmd.PersistentFlags().BoolP("help", "h", false, "Print usage") rootCmd.PersistentFlags().MarkShorthandDeprecated("help", "please use --help") }
func ActsAsRootCommand(cmd *cobra.Command, groups ...CommandGroup) FlagExposer { if cmd == nil { panic("nil root command") } cmd.SetHelpTemplate(MainHelpTemplate()) templater := &templater{ RootCmd: cmd, UsageTemplate: MainUsageTemplate(), CommandGroups: groups, } cmd.SetUsageFunc(templater.UsageFunc()) return templater }
// SetupRootCommand sets default usage, help, and error handling for the // root command. func SetupRootCommand(rootCmd *cobra.Command) { cobra.AddTemplateFunc("hasSubCommands", hasSubCommands) cobra.AddTemplateFunc("hasManagementSubCommands", hasManagementSubCommands) cobra.AddTemplateFunc("operationSubCommands", operationSubCommands) cobra.AddTemplateFunc("managementSubCommands", managementSubCommands) rootCmd.SetUsageTemplate(usageTemplate) rootCmd.SetHelpTemplate(helpTemplate) rootCmd.SetFlagErrorFunc(FlagErrorFunc) rootCmd.PersistentFlags().BoolP("help", "h", false, "Print usage") rootCmd.PersistentFlags().MarkShorthandDeprecated("help", "please use --help") }