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


Golang Context.Args方法代碼示例

本文整理匯總了Golang中github.com/gpmgo/gopm/modules/cli.Context.Args方法的典型用法代碼示例。如果您正苦於以下問題:Golang Context.Args方法的具體用法?Golang Context.Args怎麽用?Golang Context.Args使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/gpmgo/gopm/modules/cli.Context的用法示例。


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

示例1: runTest

func runTest(ctx *cli.Context) {
	if err := setup(ctx); err != nil {
		errors.SetError(err)
		return
	}

	if err := linkVendors(ctx, ""); err != nil {
		errors.SetError(err)
		return
	}

	log.Info("Testing...")

	cmdArgs := []string{"go", "test"}
	if len(ctx.String("tags")) > 0 {
		cmdArgs = append(cmdArgs, "-tags")
		cmdArgs = append(cmdArgs, ctx.String("tags"))
	}
	if ctx.IsSet("verbose") {
		cmdArgs = append(cmdArgs, "-v")
	}
	cmdArgs = append(cmdArgs, ctx.Args()...)
	if err := execCmd(setting.DefaultVendor, setting.WorkDir, cmdArgs...); err != nil {
		errors.SetError(fmt.Errorf("fail to run program: %v", err))
		return
	}

	log.Info("Command executed successfully!")
}
開發者ID:CowLeo,項目名稱:gopm,代碼行數:29,代碼來源:test.go

示例2: runTest

func runTest(ctx *cli.Context) {
	if err := setup(ctx); err != nil {
		errors.SetError(err)
		return
	}

	os.RemoveAll(setting.DefaultVendor)
	if !setting.Debug {
		defer os.RemoveAll(setting.DefaultVendor)
	}

	if err := linkVendors(ctx, ""); err != nil {
		errors.SetError(err)
		return
	}

	log.Info("Testing...")

	cmdArgs := []string{"go", "test"}
	cmdArgs = append(cmdArgs, ctx.Args()...)
	if err := execCmd(setting.DefaultVendor, setting.WorkDir, cmdArgs...); err != nil {
		errors.SetError(fmt.Errorf("fail to run program: %v", err))
		return
	}

	log.Info("Command executed successfully!")
}
開發者ID:juqkai,項目名稱:gopm,代碼行數:27,代碼來源:test.go

示例3: getByPaths

func getByPaths(ctx *cli.Context) error {
	nodes := make([]*doc.Node, 0, len(ctx.Args()))
	for _, info := range ctx.Args() {
		pkgPath := info
		n := doc.NewNode(pkgPath, doc.BRANCH, "", !ctx.Bool("download"))

		if i := strings.Index(info, "@"); i > -1 {
			pkgPath = info[:i]
			tp, val, err := validPkgInfo(info[i+1:])
			if err != nil {
				return err
			}
			n = doc.NewNode(pkgPath, tp, val, !ctx.Bool("download"))
		}

		// Check package name.
		if !strings.Contains(pkgPath, "/") {
			tmpPath, err := setting.GetPkgFullPath(pkgPath)
			if err != nil {
				return err
			}
			if tmpPath != pkgPath {
				n = doc.NewNode(tmpPath, n.Type, n.Value, n.IsGetDeps)
			}
		}
		nodes = append(nodes, n)
	}
	return getPackages(".", ctx, nodes)
}
開發者ID:yonglehou,項目名稱:gopm,代碼行數:29,代碼來源:get.go

示例4: runConfigUnset

func runConfigUnset(ctx *cli.Context) {
	if err := setup(ctx); err != nil {
		errors.SetError(err)
		return
	}

	if len(ctx.Args()) != 1 {
		errors.SetError(fmt.Errorf("Incorrect number of arguments for command: should have 1"))
		return
	}

	var err error
	switch ctx.Args().First() {
	case "proxy":
		err = setting.DeleteConfigOption("settings", "HTTP_PROXY")
	case "github":
		if err = setting.DeleteConfigOption("github", "CLIENT_ID"); err != nil {
			errors.SetError(err)
			return
		}
		err = setting.DeleteConfigOption("github", "CLIENT_SECRET")
	}
	if err != nil {
		errors.SetError(err)
		return
	}
}
開發者ID:juqkai,項目名稱:gopm,代碼行數:27,代碼來源:config.go

示例5: runBuild

func runBuild(ctx *cli.Context) {
	if err := setup(ctx); err != nil {
		errors.SetError(err)
		return
	}

	if err := buildBinary(ctx, ctx.Args()...); err != nil {
		errors.SetError(err)
		return
	}

	log.Info("Command executed successfully!")
}
開發者ID:happy214117,項目名稱:gopm,代碼行數:13,代碼來源:build.go

示例6: runConfigSetProxy

func runConfigSetProxy(ctx *cli.Context) {
	if err := setup(ctx); err != nil {
		errors.SetError(err)
		return
	}

	if len(ctx.Args()) != 1 {
		errors.SetError(fmt.Errorf("Incorrect number of arguments for command: should have 1"))
		return
	}
	if err := setting.SetConfigValue("settings", "HTTP_PROXY", ctx.Args().First()); err != nil {
		errors.SetError(err)
		return
	}
}
開發者ID:juqkai,項目名稱:gopm,代碼行數:15,代碼來源:config.go

示例7: runBuild

func runBuild(ctx *cli.Context) {
	if err := setup(ctx); err != nil {
		errors.SetError(err)
		return
	}

	os.RemoveAll(setting.DefaultVendor)
	if !setting.Debug {
		defer os.RemoveAll(setting.DefaultVendor)
	}
	if err := buildBinary(ctx, ctx.Args()...); err != nil {
		errors.SetError(err)
		return
	}

	log.Info("Command executed successfully!")
}
開發者ID:juqkai,項目名稱:gopm,代碼行數:17,代碼來源:build.go

示例8: runConfigGet

func runConfigGet(ctx *cli.Context) {
	if err := setup(ctx); err != nil {
		errors.SetError(err)
		return
	}

	if len(ctx.Args()) != 1 {
		errors.SetError(fmt.Errorf("Incorrect number of arguments for command: should have 1"))
		return
	}
	switch ctx.Args().First() {
	case "proxy":
		fmt.Printf("[%s]\n", "settings")
		showSettingString("settings", "HTTP_PROXY")
	case "github":
		fmt.Printf("[%s]\n", "github")
		showSettingString("github", "CLIENT_ID")
		showSettingString("github", "CLIENT_SECRET")
	}
}
開發者ID:juqkai,項目名稱:gopm,代碼行數:20,代碼來源:config.go

示例9: runGet

func runGet(ctx *cli.Context) {
	if err := setup(ctx); err != nil {
		errors.SetError(err)
		return
	}

	// Check option conflicts.
	hasConflict := false
	names := ""
	switch {
	case ctx.Bool("local") && ctx.Bool("gopath"):
		hasConflict = true
		names = "'--local, -l' and '--gopath, -g'"
	case ctx.Bool("local") && ctx.Bool("remote"):
		hasConflict = true
		names = "'--local, -l' and '--remote, -r'"
	case ctx.Bool("gopath") && ctx.Bool("remote"):
		hasConflict = true
		names = "'--gopath, -g' and '--remote, -r'"
	}
	if hasConflict {
		errors.SetError(fmt.Errorf("Command options have conflicts: %s", names))
		return
	}

	var err error
	// Check number of arguments to decide which function to call.
	if len(ctx.Args()) == 0 {
		if ctx.Bool("download") {
			errors.SetError(fmt.Errorf("Not enough arguments for option: '--download, -d'"))
			return
		}
		err = getByGopmfile(ctx)
	} else {
		err = getByPaths(ctx)
	}
	if err != nil {
		errors.SetError(err)
	}
}
開發者ID:yonglehou,項目名稱:gopm,代碼行數:40,代碼來源:get.go

示例10: runGet

func runGet(ctx *cli.Context) {
	if err := setup(ctx); err != nil {
		errors.SetError(err)
		return
	}

	// Check option conflicts.
	hasConflict := false
	names := ""
	switch {
	case ctx.Bool("local") && ctx.Bool("gopath"):
		hasConflict = true
		names = "'--local, -l' and '--gopath, -g'"
	case ctx.Bool("local") && ctx.Bool("remote"):
		hasConflict = true
		names = "'--local, -l' and '--remote, -r'"
	case ctx.Bool("gopath") && ctx.Bool("remote"):
		hasConflict = true
		names = "'--gopath, -g' and '--remote, -r'"
	}
	if hasConflict {
		errors.SetError(fmt.Errorf("Command options have conflicts: %s", names))
		return
	}

	var err error
	// Check number of arguments to decide which function to call.
	if len(ctx.Args()) == 0 {
		if ctx.Bool("download") {
			errors.SetError(fmt.Errorf("Not enough arguments for option: '--download, -d'"))
			return
		}
		err = getByGopmfile(ctx)
	} else {
		err = getByPaths(ctx)
	}
	if err != nil {
		errors.SetError(err)
		return
	}

	if len(ctx.Args()) > 0 && ctx.Bool("save") {
		gf, _, err := parseGopmfile(setting.GOPMFILE)
		if err != nil {
			errors.SetError(err)
			return
		}

		for _, info := range ctx.Args() {
			if i := strings.Index(info, "@"); i > -1 {
				gf.SetValue("deps", info[:i], info[i+1:])
			} else {
				gf.SetValue("deps", info, "")
			}
		}
		setting.SaveGopmfile(gf, setting.GOPMFILE)
	}
}
開發者ID:Zuozuohao,項目名稱:gopm,代碼行數:58,代碼來源:get.go

示例11: runConfigSetGitHub

func runConfigSetGitHub(ctx *cli.Context) {
	if err := setup(ctx); err != nil {
		errors.SetError(err)
		return
	}

	if len(ctx.Args()) != 2 {
		errors.SetError(fmt.Errorf("Incorrect number of arguments for command: should have 2"))
		return
	}
	if err := setting.SetConfigValue("github", "CLIENT_ID", ctx.Args().First()); err != nil {
		errors.SetError(err)
		return
	}
	if err := setting.SetConfigValue("github", "CLIENT_SECRET", ctx.Args().Get(1)); err != nil {
		errors.SetError(err)
		return
	}
}
開發者ID:juqkai,項目名稱:gopm,代碼行數:19,代碼來源:config.go

示例12: runBin

func runBin(ctx *cli.Context) {
	if err := setup(ctx); err != nil {
		errors.SetError(err)
		return
	}

	if len(ctx.Args()) != 1 {
		errors.SetError(fmt.Errorf("Incorrect number of arguments for command: should have 1"))
		return
	}

	// Check if given directory exists if specified.
	if ctx.IsSet("dir") && !base.IsDir(ctx.String("dir")) {
		errors.SetError(fmt.Errorf("Indicated path does not exist or not a directory"))
		return
	}

	// Parse package version.
	info := ctx.Args().First()
	pkgPath := info
	n := doc.NewNode(pkgPath, doc.BRANCH, "", true)
	if i := strings.Index(info, "@"); i > -1 {
		pkgPath = info[:i]
		var err error
		tp, val, err := validPkgInfo(info[i+1:])
		if err != nil {
			errors.SetError(err)
			return
		}
		n = doc.NewNode(pkgPath, tp, val, !ctx.Bool("download"))
	}

	// Check package name.
	if !strings.Contains(pkgPath, "/") {
		tmpPath, err := setting.GetPkgFullPath(pkgPath)
		if err != nil {
			errors.SetError(err)
			return
		}
		if tmpPath != pkgPath {
			n = doc.NewNode(tmpPath, n.Type, n.Value, n.IsGetDeps)
		}
	}

	if err := downloadPackages(".", ctx, []*doc.Node{n}); err != nil {
		errors.SetError(err)
		return
	}

	// Check if previous steps were successful.
	if !n.IsExist() {
		errors.SetError(fmt.Errorf("Download steps weren't successful"))
		return
	}

	tmpVendor := path.Join("vendor", path.Base(n.RootPath))
	os.RemoveAll(tmpVendor)
	os.RemoveAll(setting.VENDOR)
	// TODO: should use .gopm/temp path.
	if err := autoLink(n.InstallPath, tmpVendor); err != nil {
		errors.SetError(fmt.Errorf("Fail to link slef: %v", err))
		return
	}
	os.Chdir(tmpVendor)
	oldWorkDir := setting.WorkDir
	setting.WorkDir = path.Join(setting.WorkDir, tmpVendor)
	if !setting.Debug {
		defer func() {
			os.Chdir(oldWorkDir)
			os.RemoveAll("vendor")
			os.RemoveAll(setting.VENDOR)
		}()
	}

	// if err := buildBinary(ctx); err != nil {
	// 	errors.SetError(err)
	// 	return
	// }

	if err := linkVendors(ctx, n.ImportPath); err != nil {
		errors.SetError(err)
		return
	}

	log.Info("Installing...")

	cmdArgs := []string{"go", "install"}
	if ctx.Bool("verbose") {
		cmdArgs = append(cmdArgs, "-v")
	}
	cmdArgs = append(cmdArgs, n.ImportPath)
	if err := execCmd(setting.DefaultVendor, setting.WorkDir, cmdArgs...); err != nil {
		errors.SetError(fmt.Errorf("fail to run program: %v", err))
		return
	}

	gf, _, err := parseGopmfile(setting.GOPMFILE)
	if err != nil {
		errors.SetError(err)
		return
//.........這裏部分代碼省略.........
開發者ID:juqkai,項目名稱:gopm,代碼行數:101,代碼來源:bin.go


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