本文整理汇总了Golang中github.com/swan-go/gopm/modules/cli.Context.Args方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Args方法的具体用法?Golang Context.Args怎么用?Golang Context.Args使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/swan-go/gopm/modules/cli.Context
的用法示例。
在下文中一共展示了Context.Args方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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
}
}
示例2: 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"))
}
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!")
}
示例3: 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!")
}
示例4: 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
}
}
示例5: 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")
}
}
示例6: 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
}
}
示例7: 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
}
// Backup exsited .vendor.
if base.IsExist(setting.VENDOR) {
os.Rename(setting.VENDOR, setting.VENDOR+".bak")
defer func() {
os.Rename(setting.VENDOR+".bak", setting.VENDOR)
}()
}
// 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, dwn, err := validPkgInfo(info[i+1:])
if err != nil {
errors.SetError(err)
return
}
n = doc.NewNode(pkgPath, tp, val, dwn, !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.DownloadURL, 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)
defer func() {
os.RemoveAll(tmpVendor)
os.RemoveAll(setting.VENDOR)
}()
// FIXME: 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...")
//.........这里部分代码省略.........