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


Golang cli.Context类代码示例

本文整理汇总了Golang中github.com/gpmgo/gopm/modules/cli.Context的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getByGopmfile

func getByGopmfile(ctx *cli.Context) error {
	// Make sure gopmfile exists and up-to-date.
	gf, target, err := parseGopmfile(setting.GOPMFILE)
	if err != nil {
		return err
	}

	imports, err := getDepList(ctx, target, setting.WorkDir, setting.DefaultVendor)
	if err != nil {
		return err
	}

	// Check if dependency has version.
	nodes := make([]*doc.Node, 0, len(imports))
	for _, name := range imports {
		name = doc.GetRootPath(name)
		n := doc.NewNode(name, doc.BRANCH, "", !ctx.Bool("download"))

		// Check if user specified the version.
		if v := gf.MustValue("deps", name); len(v) > 0 {
			n.Type, n.Value, err = validPkgInfo(v)
			n = doc.NewNode(name, n.Type, n.Value, !ctx.Bool("download"))
		}
		nodes = append(nodes, n)
	}

	return getPackages(target, ctx, nodes)
}
开发者ID:yonglehou,项目名称:gopm,代码行数:28,代码来源:get.go

示例2: getDepList

// getDepList gets list of dependencies in root path format and nature order.
func getDepList(ctx *cli.Context, target, pkgPath, vendor string) ([]string, error) {
	vendorSrc := path.Join(vendor, "src")
	rootPath := doc.GetRootPath(target)
	// If work directory is not in GOPATH, then need to setup a vendor path.
	if !setting.HasGOPATHSetting || !strings.HasPrefix(pkgPath, setting.InstallGopath) {
		// Make link of self.
		log.Debug("Linking %s...", rootPath)
		from := pkgPath
		to := path.Join(vendorSrc, rootPath)
		if setting.Debug {
			log.Debug("Linking from %s to %s", from, to)
		}
		if err := autoLink(from, to); err != nil {
			return nil, err
		}
	}

	imports, err := doc.ListImports(target, rootPath, vendor, pkgPath, ctx.String("tags"), ctx.Bool("test"))
	if err != nil {
		return nil, err
	}

	list := make([]string, 0, len(imports))
	for _, name := range imports {
		name = doc.GetRootPath(name)
		if !base.IsSliceContainsStr(list, name) {
			list = append(list, name)
		}
	}
	sort.Strings(list)
	return list, nil
}
开发者ID:RouGang,项目名称:gopm,代码行数:33,代码来源:list.go

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

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

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

	os.RemoveAll(path.Join(setting.HomeDir, ".gopm/temp"))
	if ctx.Bool("all") {
		os.RemoveAll(setting.InstallRepoPath)
	}
}
开发者ID:Goyoo,项目名称:codis-docker,代码行数:11,代码来源:clean.go

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

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

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

示例9: getPackages

func getPackages(target string, ctx *cli.Context, nodes []*doc.Node) error {
	if err := downloadPackages(target, ctx, nodes); err != nil {
		return err
	}
	if err := setting.SaveLocalNodes(); err != nil {
		return err
	}

	log.Info("%d package(s) downloaded, %d failed", downloadCount, failConut)
	if ctx.GlobalBool("strict") && failConut > 0 && !setting.LibraryMode {
		return fmt.Errorf("fail to download some packages")
	}
	return nil
}
开发者ID:yonglehou,项目名称:gopm,代码行数:14,代码来源:get.go

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

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

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

示例13: buildBinary

func buildBinary(ctx *cli.Context, args ...string) error {
	_, target, err := parseGopmfile(setting.GOPMFILE)
	if err != nil {
		return err
	}

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

	log.Info("Building...")

	cmdArgs := append([]string{"go", "build"}, args...)

	// Set output binary name
	cmdArgs = append(cmdArgs, "-o")
	if ctx.IsSet("o") {
		cmdArgs = append(cmdArgs, ctx.String("o"))
	} else {
		cmdArgs = append(cmdArgs, path.Base(target))
	}

	if len(ctx.String("tags")) > 0 {
		cmdArgs = append(cmdArgs, "-tags")
		cmdArgs = append(cmdArgs, ctx.String("tags"))
	}

	log.Debug("Args: %v", cmdArgs)

	if err := execCmd(setting.DefaultVendor, setting.WorkDir, cmdArgs...); err != nil {
		return fmt.Errorf("fail to build program: %v", err)
	}

	if setting.IsWindowsXP {
		fName := path.Base(target)
		binName := fName + ".exe"
		os.Remove(binName)
		exePath := path.Join(setting.DefaultVendorSrc, target, binName)
		if base.IsFile(exePath) {
			if err := os.Rename(exePath, path.Join(setting.WorkDir, binName)); err != nil {
				return fmt.Errorf("fail to move binary: %v", err)
			}
		} else {
			log.Warn("No binary generated")
		}
	}
	return nil
}
开发者ID:Zuozuohao,项目名称:gopm,代码行数:48,代码来源:build.go

示例14: runInstall

func runInstall(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
	}

	// Get target name.
	gfPath := path.Join(setting.WorkDir, setting.GOPMFILE)
	_, target, err := parseGopmfile(gfPath)
	if err != nil {
		errors.SetError(fmt.Errorf("fail to parse gopmfile: %v", err))
		return
	}

	log.Info("Installing...")

	cmdArgs := []string{"go", "install"}
	if ctx.Bool("verbose") {
		cmdArgs = append(cmdArgs, "-v")
	}
	cmdArgs = append(cmdArgs, target)
	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,代码行数:38,代码来源:install.go

示例15: downloadPackage

// downloadPackage downloads package either use version control tools or not.
func downloadPackage(ctx *cli.Context, n *doc.Node) (*doc.Node, []string, error) {

	// fmt.Println(n.VerString())
	log.Info("Downloading package: %s", n.VerString())
	downloadCache.Set(n.VerString())

	vendor := base.GetTempDir()
	defer os.RemoveAll(vendor)

	var (
		err     error
		imports []string
		srcPath string
	)

	// Check if only need to use VCS tools.
	vcs := doc.GetVcsName(n.InstallGopath)
	// If update, gopath and VCS tools set then use VCS tools to update the package.
	if ctx.Bool("update") && (ctx.Bool("gopath") || ctx.Bool("local")) && len(vcs) > 0 {
		if err = n.UpdateByVcs(vcs); err != nil {
			return nil, nil, fmt.Errorf("fail to update by VCS(%s): %v", n.ImportPath, err)
		}
		srcPath = n.InstallGopath
	} else {
		if !n.IsGetDepsOnly || !n.IsExist() {
			// Get revision value from local records.
			n.Revision = setting.LocalNodes.MustValue(n.RootPath, "value")
			if err = n.DownloadGopm(ctx); err != nil {
				errors.AppendError(errors.NewErrDownload(n.ImportPath + ": " + err.Error()))
				failConut++
				os.RemoveAll(n.InstallPath)
				return nil, nil, nil
			}
		}
		srcPath = n.InstallPath
	}

	if n.IsGetDeps {
		imports, err = getDepList(ctx, n.ImportPath, srcPath, vendor)
		if err != nil {
			return nil, nil, fmt.Errorf("fail to list imports(%s): %v", n.ImportPath, err)
		}
		if setting.Debug {
			log.Debug("New imports: %v", imports)
		}
	}
	return n, imports, err
}
开发者ID:yonglehou,项目名称:gopm,代码行数:49,代码来源:get.go


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