當前位置: 首頁>>代碼示例>>Golang>>正文


Golang cobra.Command類代碼示例

本文整理匯總了Golang中github.com/appc/acbuild/Godeps/_workspace/src/github.com/spf13/cobra.Command的典型用法代碼示例。如果您正苦於以下問題:Golang Command類的具體用法?Golang Command怎麽用?Golang Command使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Command類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: runRmDep

func runRmDep(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}
	if len(args) != 1 {
		stderr("dependency remove: incorrect number of arguments")
		return 1
	}

	lockfile, err := getLock()
	if err != nil {
		stderr("dependency remove: %v", err)
		return 1
	}
	defer func() {
		if err := releaseLock(lockfile); err != nil {
			stderr("dependency remove: %v", err)
			exit = 1
		}
	}()

	if debug {
		stderr("Removing dependency %q", args[0])
	}

	err = lib.RemoveDependency(tmpacipath(), args[0])

	if err != nil {
		stderr("dependency remove: %v", err)
		return 1
	}

	return 0
}
開發者ID:apcera,項目名稱:acbuild,代碼行數:35,代碼來源:dependency.go

示例2: runRun

func runRun(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}

	lockfile, err := getLock()
	if err != nil {
		stderr("run: %v", err)
		return 1
	}
	defer func() {
		if err := releaseLock(lockfile); err != nil {
			stderr("run: %v", err)
			exit = 1
		}
	}()

	if debug {
		stderr("Running: %v", args)
	}

	err = lib.Run(tmpacipath(), depstorepath(), targetpath(), scratchpath(), workpath(), args, insecure)

	if err != nil {
		stderr("run: %v", err)
		return 1
	}

	return 0
}
開發者ID:apcera,項目名稱:acbuild,代碼行數:31,代碼來源:run.go

示例3: runAddLabel

func runAddLabel(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}
	if len(args) != 2 {
		stderr("label add: incorrect number of arguments")
		return 1
	}

	lockfile, err := getLock()
	if err != nil {
		stderr("label add: %v", err)
		return 1
	}
	defer func() {
		if err := releaseLock(lockfile); err != nil {
			stderr("label add: %v", err)
			exit = 1
		}
	}()

	if debug {
		stderr("Adding label %q=%q", args[0], args[1])
	}

	err = lib.AddLabel(tmpacipath(), args[0], args[1])

	if err != nil {
		stderr("label add: %v", err)
		return 1
	}

	return 0
}
開發者ID:apcera,項目名稱:acbuild,代碼行數:35,代碼來源:label.go

示例4: runAddMount

func runAddMount(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}
	if len(args) != 2 {
		stderr("mount add: incorrect number of arguments")
		return 1
	}

	if debug {
		if readOnly {
			stderr("Adding read only mount point %q=%q", args[0], args[1])
		} else {
			stderr("Adding mount point %q=%q", args[0], args[1])
		}
	}

	err := newACBuild().AddMount(args[0], args[1], readOnly)

	if err != nil {
		stderr("mount add: %v", err)
		return 1
	}

	return 0
}
開發者ID:aaronlevy,項目名稱:acbuild,代碼行數:27,代碼來源:mount.go

示例5: runSetGroup

func runSetGroup(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}
	if len(args) != 1 {
		stderr("set-group: incorrect number of arguments")
		return 1
	}

	lockfile, err := getLock()
	if err != nil {
		stderr("set-group: %v", err)
		return 1
	}
	defer func() {
		if err := releaseLock(lockfile); err != nil {
			stderr("set-group: %v", err)
			exit = 1
		}
	}()

	if debug {
		stderr("Setting group to %s", args[0])
	}

	err = lib.SetGroup(tmpacipath(), args[0])

	if err != nil {
		stderr("set-group: %v", err)
		return 1
	}

	return 0
}
開發者ID:apcera,項目名稱:acbuild,代碼行數:35,代碼來源:set-group.go

示例6: 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:rhencke,項目名稱:acbuild,代碼行數:35,代碼來源:acbuild.go

示例7: runCopy

func runCopy(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}
	if (!toDir && len(args) != 2) || (toDir && len(args) < 2) {
		stderr("copy: incorrect number of arguments")
		return 1
	}

	if debug {
		stderr("Copying host:%s to aci:%s", args[0], args[1])
	}

	var err error
	if toDir {
		err = newACBuild().CopyToDir(args[:len(args)-1], args[len(args)-1])
	} else {
		err = newACBuild().CopyToTarget(args[0], args[1])
	}

	if err != nil {
		stderr("copy: %v", err)
		return getErrorCode(err)
	}

	return 0
}
開發者ID:rhencke,項目名稱:acbuild,代碼行數:28,代碼來源:copy.go

示例8: runCopy

func runCopy(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}
	if len(args) != 2 {
		stderr("copy: incorrect number of arguments")
		return 1
	}

	lockfile, err := getLock()
	if err != nil {
		stderr("copy: %v", err)
		return 1
	}
	defer func() {
		if err := releaseLock(lockfile); err != nil {
			stderr("copy: %v", err)
			exit = 1
		}
	}()

	if debug {
		stderr("Copying host:%s to aci:%s", args[0], args[1])
	}

	err = lib.Copy(tmpacipath(), args[0], args[1])

	if err != nil {
		stderr("copy: %v", err)
		return 1
	}

	return 0
}
開發者ID:apcera,項目名稱:acbuild,代碼行數:35,代碼來源:copy.go

示例9: runAddPort

func runAddPort(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}
	if len(args) != 3 {
		stderr("port add: incorrect number of arguments")
		return 1
	}
	port, err := strconv.ParseUint(args[2], 10, 16)
	if err != nil {
		stderr("port add: port must be a positive number between 0 and 65535")
		return 1
	}

	if debug {
		stderr("Adding port %q=%q", args[0], args[1])
	}

	err = newACBuild().AddPort(args[0], args[1], uint(port), count, socketActivated)

	if err != nil {
		stderr("port add: %v", err)
		return getErrorCode(err)
	}

	return 0
}
開發者ID:kinvolk,項目名稱:acbuild,代碼行數:28,代碼來源:port.go

示例10: runRemoveEnv

func runRemoveEnv(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}
	if len(args) > 1 {
		stderr("environment remove: incorrect number of arguments")
		return 1
	}

	lockfile, err := getLock()
	if err != nil {
		stderr("environment remove: %v", err)
		return 1
	}
	defer func() {
		if err := releaseLock(lockfile); err != nil {
			stderr("environment remove: %v", err)
			exit = 1
		}
	}()

	if debug {
		stderr("Removing environment variable %q", args[0])
	}

	err = lib.RemoveEnv(tmpacipath(), args[0])

	if err != nil {
		stderr("environment remove: %v", err)
		return 1
	}

	return 0
}
開發者ID:apcera,項目名稱:acbuild,代碼行數:35,代碼來源:environment.go

示例11: getSubCommands

func getSubCommands(cmd *cobra.Command) []*cobra.Command {
	subCommands := []*cobra.Command{}
	for _, subCmd := range cmd.Commands() {
		subCommands = append(subCommands, subCmd)
		subCommands = append(subCommands, getSubCommands(subCmd)...)
	}
	return subCommands
}
開發者ID:jaypipes,項目名稱:acbuild,代碼行數:8,代碼來源:acbuild.go

示例12: runAddDep

func runAddDep(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}
	if len(args) != 1 {
		stderr("dependency add: incorrect number of arguments")
		return 1
	}

	if debug {
		stderr("Adding dependency %q", args[0])
	}

	app, err := discovery.NewAppFromString(args[0])
	if err != nil {
		stderr("dependency add: couldn't parse dependency name: %v", err)
		return 1
	}

	appcLabels := types.Labels(labels)

	for name, value := range app.Labels {
		if _, ok := appcLabels.Get(string(name)); ok {
			stderr("multiple %s labels specified", name)
			return 1
		}
		appcLabels = append(appcLabels, types.Label{
			Name:  name,
			Value: value,
		})
	}

	var hash *types.Hash
	if imageId != "" {
		var err error
		hash, err = types.NewHash(imageId)
		if err != nil {
			stderr("dependency add: couldn't parse image ID: %v", err)
			return 1
		}
	}

	err = newACBuild().AddDependency(app.Name, hash, appcLabels, size)

	if err != nil {
		stderr("dependency add: %v", err)
		return getErrorCode(err)
	}

	return 0
}
開發者ID:rhencke,項目名稱:acbuild,代碼行數:52,代碼來源:dependency.go

示例13: usageFunc

func usageFunc(cmd *cobra.Command) error {
	subCommands := getSubCommands(cmd)
	commandUsageTemplate.Execute(tabOut, struct {
		Executable  string
		Cmd         *cobra.Command
		CmdFlags    *pflag.FlagSet
		SubCommands []*cobra.Command
	}{
		cliName,
		cmd,
		cmd.Flags(),
		subCommands,
	})
	tabOut.Flush()
	return nil
}
開發者ID:jaypipes,項目名稱:acbuild,代碼行數:16,代碼來源:acbuild.go

示例14: runCat

func runCat(cmd *cobra.Command, args []string) (exit int) {
	if len(args) != 0 {
		cmd.Usage()
		return 1
	}

	if debug {
		stderr("Printing manifest from current build")
	}

	err := newACBuild().CatManifest(prettyPrint)
	if err != nil {
		stderr("cat-manifest: %v", err)
		return 1
	}

	return 0
}
開發者ID:kinvolk,項目名稱:acbuild,代碼行數:18,代碼來源:cat-manifest.go

示例15: runRun

func runRun(cmd *cobra.Command, args []string) (exit int) {
	if len(args) == 0 {
		cmd.Usage()
		return 1
	}

	if debug {
		stderr("Running: %v", args)
	}

	err := lib.Run(tmpacipath(), depstorepath(), targetpath(), scratchpath(), workpath(), args, insecure)

	if err != nil {
		stderr("run: %v", err)
		return 1
	}

	return 0
}
開發者ID:jaypipes,項目名稱:acbuild,代碼行數:19,代碼來源:run.go


注:本文中的github.com/appc/acbuild/Godeps/_workspace/src/github.com/spf13/cobra.Command類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。