本文整理汇总了Golang中github.com/spf13/cobra.Command.SetUsageFunc方法的典型用法代码示例。如果您正苦于以下问题:Golang Command.SetUsageFunc方法的具体用法?Golang Command.SetUsageFunc怎么用?Golang Command.SetUsageFunc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/spf13/cobra.Command
的用法示例。
在下文中一共展示了Command.SetUsageFunc方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: UseOptionsTemplates
func UseOptionsTemplates(cmd *cobra.Command) {
cmd.SetHelpTemplate(OptionsHelpTemplate())
templater := &templater{
UsageTemplate: OptionsUsageTemplate(),
}
cmd.SetUsageFunc(templater.UsageFunc())
}
示例2: Namespace
// Namespace enables namespacing for a sub-commmand and its immediated children. It returns an error if the command does not have a parent.
func (n *CobraNamespace) Namespace(cmd *cobra.Command) error {
if !cmd.HasParent() {
return errors.New("cmdns: command requires a parent")
}
// Do not bind if there are not available sub commands
if !cmd.HasAvailableSubCommands() {
return nil
}
if n.OverrideUsageFunc {
cmd.SetUsageFunc(n.UsageFunc())
}
for _, c := range cmd.Commands() {
if !c.IsAvailableCommand() {
continue
}
// copy the command add it to the root command with a prefix of its parent.
nc := *c
nc.Use = cmd.Name() + DefaultNamespaceSeparator + c.Use
// add this command to the root and hide it so it does not show in available commands list
c.Parent().Parent().AddCommand(&nc)
c.Hidden = true
n.commands = append(n.commands, &nc)
}
n.cmd = cmd
return nil
}
示例3: ActsAsRootCommand
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
}
示例4: ExposeFlags
func (templater *templater) ExposeFlags(cmd *cobra.Command, flags ...string) FlagExposer {
cmd.SetUsageFunc(templater.UsageFunc(flags...))
return templater
}
示例5: Enable
// Enable enables monocle on a cobra command
func (m *Monocle) Enable(c *cobra.Command) {
m.Command = c
c.SetUsageFunc(m.UsageFunc())
}