本文整理汇总了Golang中github.com/spf13/cobra.Command.Example方法的典型用法代码示例。如果您正苦于以下问题:Golang Command.Example方法的具体用法?Golang Command.Example怎么用?Golang Command.Example使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/spf13/cobra.Command
的用法示例。
在下文中一共展示了Command.Example方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: adjustCmdExamples
func adjustCmdExamples(cmd *cobra.Command, parentName string, name string) {
for _, subCmd := range cmd.Commands() {
adjustCmdExamples(subCmd, parentName, cmd.Name())
}
cmd.Example = strings.Replace(cmd.Example, "kubectl", parentName, -1)
tabbing := " "
examples := []string{}
scanner := bufio.NewScanner(strings.NewReader(cmd.Example))
for scanner.Scan() {
examples = append(examples, tabbing+strings.TrimSpace(scanner.Text()))
}
cmd.Example = strings.Join(examples, "\n")
}
示例2: ReplaceCommandName
// ReplaceCommandName recursively processes the examples in a given command to change a hardcoded
// command name (like 'kubectl' to the appropriate target name). It returns c.
func ReplaceCommandName(from, to string, c *cobra.Command) *cobra.Command {
c.Example = strings.Replace(c.Example, from, to, -1)
for _, sub := range c.Commands() {
ReplaceCommandName(from, to, sub)
}
return c
}
示例3: Normalize
// Normalize perform all required normalizations on a given command.
func Normalize(cmd *cobra.Command) *cobra.Command {
if len(cmd.Long) > 0 {
cmd.Long = LongDesc(cmd.Long)
}
if len(cmd.Example) > 0 {
cmd.Example = Examples(cmd.Example)
}
return cmd
}