本文整理汇总了Golang中github.com/spf13/cobra.Command.HasAvailableSubCommands方法的典型用法代码示例。如果您正苦于以下问题:Golang Command.HasAvailableSubCommands方法的具体用法?Golang Command.HasAvailableSubCommands怎么用?Golang Command.HasAvailableSubCommands使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/spf13/cobra.Command
的用法示例。
在下文中一共展示了Command.HasAvailableSubCommands方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}