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


Golang Command.Name方法代码示例

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


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

示例1: GetFlagBool

func GetFlagBool(cmd *cobra.Command, flag string) bool {
	b, err := cmd.Flags().GetBool(flag)
	if err != nil {
		glog.Fatalf("err accessing flag %s for command %s: %v", flag, cmd.Name(), err)
	}
	return b
}
开发者ID:ncdc,项目名称:origin,代码行数:7,代码来源:helpers.go

示例2: GetFlagString

func GetFlagString(cmd *cobra.Command, flag string) string {
	s, err := cmd.Flags().GetString(flag)
	if err != nil {
		glog.Fatalf("err %v accessing flag %s for command %s: %s", err, flag, cmd.Name())
	}
	return s
}
开发者ID:hferentschik,项目名称:origin,代码行数:7,代码来源:helpers.go

示例3: addACBuildAnnotation

func addACBuildAnnotation(cmd *cobra.Command, args []string) error {
	const annoNamePattern = "appc.io/acbuild/command-%d"

	acb := newACBuild()

	man, err := util.GetManifest(acb.CurrentACIPath)
	if err != nil {
		return err
	}

	var acbuildCount int
	for _, ann := range man.Annotations {
		var tmpCount int
		n, _ := fmt.Sscanf(string(ann.Name), annoNamePattern, &tmpCount)
		if n == 1 && tmpCount > acbuildCount {
			acbuildCount = tmpCount
		}
	}

	command := cmd.Name()
	tmpcmd := cmd.Parent()
	for {
		command = tmpcmd.Name() + " " + command
		if tmpcmd == cmdAcbuild {
			break
		}
		tmpcmd = tmpcmd.Parent()
	}

	for _, a := range args {
		command += fmt.Sprintf(" %q", a)
	}

	return acb.AddAnnotation(fmt.Sprintf(annoNamePattern, acbuildCount+1), command)
}
开发者ID:dgonyeo,项目名称:acbuild,代码行数:35,代码来源:acbuild.go

示例4: GetFlagInt

// Assumes the flag has a default value.
func GetFlagInt(cmd *cobra.Command, flag string) int {
	i, err := cmd.Flags().GetInt(flag)
	if err != nil {
		glog.Fatalf("err: %v accessing flag %s for command %s: %s", err, flag, cmd.Name())
	}
	return i
}
开发者ID:hferentschik,项目名称:origin,代码行数:8,代码来源:helpers.go

示例5: getFlag

func getFlag(cmd *cobra.Command, flag string) *pflag.Flag {
	f := cmd.Flags().Lookup(flag)
	if f == nil {
		glog.Fatalf("flag accessed but not defined for command %s: %s", cmd.Name(), flag)
	}
	return f
}
开发者ID:ncdc,项目名称:origin,代码行数:7,代码来源:helpers.go

示例6: handleBuildError

func handleBuildError(c *cobra.Command, err error, fullName string) error {
	if err == nil {
		return nil
	}
	if errs, ok := err.(errors.Aggregate); ok {
		if len(errs.Errors()) == 1 {
			err = errs.Errors()[0]
		}
	}
	switch t := err.(type) {
	case newapp.ErrNoMatch:
		return fmt.Errorf(`%[1]v

The '%[2]s' command will match arguments to the following types:

  1. Images tagged into image streams in the current project or the 'openshift' project
     - if you don't specify a tag, we'll add ':latest'
  2. Images in the Docker Hub, on remote registries, or on the local Docker engine
  3. Git repository URLs or local paths that point to Git repositories

--allow-missing-images can be used to point to an image that does not exist yet
or is only on the local system.

See '%[2]s' for examples.
`, t, c.Name())
	}
	switch err {
	case newcmd.ErrNoInputs:
		// TODO: suggest things to the user
		return cmdutil.UsageError(c, newBuildNoInput, fullName)
	default:
		return err
	}
}
开发者ID:kimsh92,项目名称:origin,代码行数:34,代码来源:newbuild.go

示例7: GetFlagStringSlice

// GetFlagStringList can be used to accept multiple argument with flag repetition (e.g. -f arg1 -f arg2 ...)
func GetFlagStringSlice(cmd *cobra.Command, flag string) []string {
	s, err := cmd.Flags().GetStringSlice(flag)
	if err != nil {
		glog.Fatalf("err accessing flag %s for command %s: %v", flag, cmd.Name(), err)
	}
	return s
}
开发者ID:ncdc,项目名称:origin,代码行数:8,代码来源:helpers.go

示例8: 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
}
开发者ID:gosuri,项目名称:cmdns,代码行数:31,代码来源:cmdns.go

示例9: GetFlagInt64

// Assumes the flag has a default value.
func GetFlagInt64(cmd *cobra.Command, flag string) int64 {
	i, err := cmd.Flags().GetInt64(flag)
	if err != nil {
		glog.Fatalf("err accessing flag %s for command %s: %v", flag, cmd.Name(), err)
	}
	return i
}
开发者ID:ncdc,项目名称:origin,代码行数:8,代码来源:helpers.go

示例10: add_container_flags

func add_container_flags(cmd *cobra.Command){
	cmd.Flags().StringP("node", "n", "", "Node name which will be API worker")
	cmd.Flags().StringSliceP("target", "t", []string{""}, "Node name where will be " + cmd.Name() + " container")
	cmd.Flags().StringSlice("group", []string{""}, "Group name whom nodes where will be " + cmd.Name() + " container")
	cmd.Flags().StringSlice("tag", []string{""}, "Tag name whom nodes where will be " + cmd.Name() + " container")
	cmd.Flags().StringP("container", "c", "", "Container name")
}
开发者ID:treescale,项目名称:treescale,代码行数:7,代码来源:commands.go

示例11: NewSubCommands

// Parse the Commands
func NewSubCommands(c *cobra.Command, path string) Commands {
	subCommands := Commands{NewCommand(c, path+c.Name())}
	for _, subCommand := range c.Commands() {
		subCommands = append(subCommands, NewSubCommands(subCommand, path+c.Name()+" ")...)
	}
	return subCommands
}
开发者ID:alex-mohr,项目名称:kubernetes,代码行数:8,代码来源:gen_slate_yaml.go

示例12: GetFlagDuration

func GetFlagDuration(cmd *cobra.Command, flag string) time.Duration {
	d, err := cmd.Flags().GetDuration(flag)
	if err != nil {
		glog.Fatalf("err accessing flag %s for command %s: %v", flag, cmd.Name(), err)
	}
	return d
}
开发者ID:ncdc,项目名称:origin,代码行数:7,代码来源:helpers.go

示例13: GetFlagString

func GetFlagString(cmd *cobra.Command, flag string) string {
	f := cmd.Flags().Lookup(flag)
	if f == nil {
		glog.Fatalf("Flag accessed but not defined for command %s: %s", cmd.Name(), flag)
	}
	return f.Value.String()
}
开发者ID:TencentSA,项目名称:kubernetes-0.5,代码行数:7,代码来源:helpers.go

示例14: 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

示例15: cmdGlobalMachineState

// cmdGlobalMachineState runs a specific fleetctl command on each target machine
// where global units are started. To avoid unnecessary ssh connections being
// alive, it filters out the list of machines as much as possible.
func cmdGlobalMachineState(cCmd *cobra.Command, globalUnits []schema.Unit) (err error) {
	cmd := cCmd.Name()
	mapUNs := map[string]string{}
	for _, unit := range globalUnits {
		m := cachedMachineState(unit.MachineID)
		if m == nil || m.ID == "" || m.PublicIP == "" {
			continue
		}
		mapUNs[m.ID] = unit.Name
	}

	// create a list of unique unit names
	resultIDs := map[string]string{}
	for id, name := range mapUNs {
		resultIDs[id] = name
	}

	for id, name := range resultIDs {
		// run a correspondent systemctl command
		if exitVal := runCommand(cCmd, id, "systemctl", cmd, name); exitVal != 0 {
			err = fmt.Errorf("Error running systemctl %s. machine id=%v, unit name=%s",
				cmd, id, name)
			break
		}
	}

	return err
}
开发者ID:jonboulle,项目名称:fleet,代码行数:31,代码来源:fleetctl.go


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