当前位置: 首页>>代码示例>>Golang>>正文


Golang Command.UseLine方法代码示例

本文整理汇总了Golang中github.com/spf13/cobra.Command.UseLine方法的典型用法代码示例。如果您正苦于以下问题:Golang Command.UseLine方法的具体用法?Golang Command.UseLine怎么用?Golang Command.UseLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/spf13/cobra.Command的用法示例。


在下文中一共展示了Command.UseLine方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: genMarkdown

func genMarkdown(command *cobra.Command, parent, docsDir string) {
	dparent := strings.Replace(parent, " ", "-", -1)
	name := command.Name()
	dname := name
	if len(parent) > 0 {
		dname = dparent + "-" + name
		name = parent + " " + name
	}

	out := new(bytes.Buffer)
	short := command.Short
	long := command.Long
	if len(long) == 0 {
		long = short
	}

	fmt.Fprintf(out, "## %s\n\n", name)
	fmt.Fprintf(out, "%s\n\n", short)
	fmt.Fprintf(out, "### Synopsis\n\n")
	fmt.Fprintf(out, "\n%s\n\n", long)

	if command.Runnable() {
		fmt.Fprintf(out, "```\n%s\n```\n\n", command.UseLine())
	}

	if len(command.Example) > 0 {
		fmt.Fprintf(out, "### Examples\n\n")
		fmt.Fprintf(out, "```\n%s\n```\n\n", command.Example)
	}

	printOptions(out, command, name)

	if len(command.Commands()) > 0 || len(parent) > 0 {
		fmt.Fprintf(out, "### SEE ALSO\n")
		if len(parent) > 0 {
			link := dparent + ".md"
			fmt.Fprintf(out, "* [%s](%s)\n", dparent, link)
		}
		for _, c := range command.Commands() {
			child := dname + "-" + c.Name()
			link := child + ".md"
			fmt.Fprintf(out, "* [%s](%s)\n", child, link)
			genMarkdown(c, name, docsDir)
		}
		fmt.Fprintf(out, "\n")
	}

	filename := docsDir + dname + ".md"
	outFile, err := os.Create(filename)
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
	defer outFile.Close()
	_, err = outFile.Write(out.Bytes())
	if err != nil {
		fmt.Println(err)
		os.Exit(1)
	}
}
开发者ID:vrosnet,项目名称:kubernetes,代码行数:60,代码来源:gen_kubectl_docs.go

示例2: usageLine

func (t *templater) usageLine(c *cobra.Command) string {
	usage := c.UseLine()
	suffix := "[options]"
	if c.HasFlags() && !strings.Contains(usage, suffix) {
		usage += " " + suffix
	}
	return usage
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:8,代码来源:templater.go

示例3: GenMarkdownCustom

func GenMarkdownCustom(cmd *cobra.Command, out io.Writer, linkHandler func(string) string) {
	name := cmd.CommandPath()

	short := cmd.Short
	long := cmd.Long
	if len(long) == 0 {
		long = short
	}

	fmt.Fprintf(out, "## %s\n\n", name)
	fmt.Fprintf(out, "%s\n\n", short)
	fmt.Fprintf(out, "### Synopsis\n\n")
	fmt.Fprintf(out, "\n%s\n\n", long)

	if cmd.Runnable() {
		fmt.Fprintf(out, "```\n%s\n```\n\n", cmd.UseLine())
	}

	if len(cmd.Example) > 0 {
		fmt.Fprintf(out, "### Examples\n\n")
		fmt.Fprintf(out, "```\n%s\n```\n\n", cmd.Example)
	}

	printOptions(out, cmd, name)
	if hasSeeAlso(cmd) {
		fmt.Fprintf(out, "### SEE ALSO\n")
		if cmd.HasParent() {
			parent := cmd.Parent()
			pname := parent.CommandPath()
			link := pname + ".md"
			link = strings.Replace(link, " ", "_", -1)
			fmt.Fprintf(out, "* [%s](%s)\t - %s\n", pname, linkHandler(link), parent.Short)
			cmd.VisitParents(func(c *cobra.Command) {
				if c.DisableAutoGenTag {
					cmd.DisableAutoGenTag = c.DisableAutoGenTag
				}
			})
		}

		children := cmd.Commands()
		sort.Sort(byName(children))

		for _, child := range children {
			if !child.IsAvailableCommand() || child.IsHelpCommand() {
				continue
			}
			cname := name + " " + child.Name()
			link := cname + ".md"
			link = strings.Replace(link, " ", "_", -1)
			fmt.Fprintf(out, "* [%s](%s)\t - %s\n", cname, linkHandler(link), child.Short)
		}
		fmt.Fprintf(out, "\n")
	}
	if !cmd.DisableAutoGenTag {
		fmt.Fprintf(out, "###### Auto generated by spf13/cobra on %s\n", time.Now().Format("2-Jan-2006"))
	}
}
开发者ID:GamerockSA,项目名称:dex,代码行数:57,代码来源:md_docs.go

示例4: scaleArgs

func scaleArgs(cmd *cobra.Command, args []string) error {
	if err := cli.RequiresMinArgs(1)(cmd, args); err != nil {
		return err
	}
	for _, arg := range args {
		if parts := strings.SplitN(arg, "=", 2); len(parts) != 2 {
			return fmt.Errorf(
				"Invalid scale specifier '%s'.\nSee '%s --help'.\n\nUsage:  %s\n\n%s",
				arg,
				cmd.CommandPath(),
				cmd.UseLine(),
				cmd.Short,
			)
		}
	}
	return nil
}
开发者ID:karunchennuri,项目名称:docker,代码行数:17,代码来源:scale.go

示例5: manPreamble

func manPreamble(out io.Writer, header *GenManHeader, cmd *cobra.Command, dashedName string) {
	description := cmd.Long
	if len(description) == 0 {
		description = cmd.Short
	}

	fmt.Fprintf(out, `%% %s(%s)%s
%% %s
%% %s
# NAME
`, header.Title, header.Section, header.date, header.Source, header.Manual)
	fmt.Fprintf(out, "%s \\- %s\n\n", dashedName, cmd.Short)
	fmt.Fprintf(out, "# SYNOPSIS\n")
	fmt.Fprintf(out, "**%s**\n\n", cmd.UseLine())
	fmt.Fprintf(out, "# DESCRIPTION\n")
	fmt.Fprintf(out, "%s\n\n", description)
}
开发者ID:tj,项目名称:cobra,代码行数:17,代码来源:man_docs.go

示例6: NoArgs

// NoArgs validate args and returns an error if there are any args
func NoArgs(cmd *cobra.Command, args []string) error {
	if len(args) == 0 {
		return nil
	}

	if cmd.HasSubCommands() {
		return fmt.Errorf("\n" + strings.TrimRight(cmd.UsageString(), "\n"))
	}

	return fmt.Errorf(
		"\"%s\" accepts no argument(s).\nSee '%s --help'.\n\nUsage:  %s\n\n%s",
		cmd.CommandPath(),
		cmd.CommandPath(),
		cmd.UseLine(),
		cmd.Short,
	)
}
开发者ID:kolyshkin,项目名称:docker,代码行数:18,代码来源:required.go

示例7: Generate

// Generate prints API docs for a command
func Generate(cmd *cobra.Command) string {
	buf := new(bytes.Buffer)

	cmds := genCmdList(cmd)
	sort.Sort(byName(cmds))
	for _, cmd := range cmds {
		if len(strings.Split(cmd.CommandPath(), " ")) == 1 {
			fmt.Fprint(buf, "**Options**\n\n")
			printOptions(buf, cmd)
			fmt.Fprintln(buf)
			continue
		}

		depth := len(strings.Split(cmd.CommandPath(), " "))

		fmt.Fprint(buf, header(depth, cmd.CommandPath()))

		fmt.Fprint(buf, cmd.Long, "\n\n")

		if cmd.Runnable() {
			fmt.Fprint(buf, "**Usage:** ", "`", cmd.UseLine(), "`", "\n\n")
		}

		if cmd.HasLocalFlags() || cmd.HasPersistentFlags() {
			fmt.Fprint(buf, "**Options**\n\n")
			printOptions(buf, cmd)
		}

		if cmd.Example != "" {
			fmt.Fprint(buf, "**Example**\n\n")
			fmt.Fprint(buf, "```", "\n", cmd.Example, "```", "\n\n")
		}
	}

	return buf.String()
}
开发者ID:TheThingsNetwork,项目名称:ttn,代码行数:37,代码来源:generate.go

示例8: GenerateSingle

func GenerateSingle(cmd *cobra.Command, out *bytes.Buffer, linkHandler func(string) string, specs []string, render_dir string) {
	name := cmd.CommandPath()

	short := cmd.Short
	long := cmd.Long
	if len(long) == 0 {
		long = short
	}

	fmt.Fprintf(out, "# %s\n\n", name)
	fmt.Fprintf(out, "%s\n\n", short)
	fmt.Fprintf(out, "## Synopsis\n")
	fmt.Fprintf(out, "\n%s\n\n", long)

	if cmd.Runnable() {
		fmt.Fprintf(out, "```bash\n%s\n```\n\n", cmd.UseLine())
	}

	if len(cmd.Example) > 0 {
		fmt.Fprintf(out, "## Examples\n\n")
		fmt.Fprintf(out, "```bash\n%s\n```\n\n", cmd.Example)
	}

	flags := cmd.NonInheritedFlags()
	flags.SetOutput(out)
	if flags.HasFlags() {
		fmt.Fprintf(out, "## Options\n\n```\n")
		flags.PrintDefaults()
		fmt.Fprintf(out, "```\n\n")
	}

	parentFlags := cmd.InheritedFlags()
	parentFlags.SetOutput(out)
	if parentFlags.HasFlags() {
		fmt.Fprintf(out, "## Options inherited from parent commands\n\n```\n")
		parentFlags.PrintDefaults()
		fmt.Fprintf(out, "```\n\n")
	}

	if len(cmd.Commands()) > 0 {
		fmt.Fprintf(out, "## Subcommands\n\n")
		children := cmd.Commands()
		sort.Sort(byName(children))

		for _, child := range children {
			if len(child.Deprecated) > 0 {
				continue
			}
			cname := name + " " + child.Name()
			link := cname + ".md"
			link = strings.Replace(link, " ", "_", -1)
			fmt.Fprintf(out, "* [%s](%s)\t - %s\n", cname, linkHandler(link), child.Short)
		}
	}

	if len(cmd.Commands()) > 0 && cmd.HasParent() {
		fmt.Fprintf(out, "\n")
	}

	if cmd.HasParent() {
		fmt.Fprintf(out, "## See Also\n\n")
		parent := cmd.Parent()
		pname := parent.CommandPath()
		link := pname + ".md"
		link = strings.Replace(link, " ", "_", -1)
		fmt.Fprintf(out, "* [%s](%s)\t - %s\n", pname, linkHandler(link), parent.Short)
	}

	fmt.Fprintf(out, "\n## Specifications\n\n")
	for _, spec := range specs {
		spec = strings.Replace(spec, render_dir, "", 1)
		title := strings.Replace(spec, "_", " ", -1)
		title = strings.Replace(title, ".md", "", 1)
		// title = strings.Replace(title, "spec", "specification", 1)
		title = strings.Title(title)
		fmt.Fprintf(out, "* [%s](%s)\n", title, linkHandler(spec))
	}

	fmt.Fprintf(out, "\n")
}
开发者ID:eris-ltd,项目名称:toadserver,代码行数:80,代码来源:docs_generator.go


注:本文中的github.com/spf13/cobra.Command.UseLine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。