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) } }
func runGen(ctx *cli.Context) { if err := setup(ctx); err != nil { errors.SetError(err) return } gfPath := path.Join(setting.WorkDir, setting.GOPMFILE) if !setting.HasGOPATHSetting && !base.IsFile(gfPath) { log.Warn("Dependency list may contain package itself without GOPATH setting and gopmfile.") } gf, target, err := parseGopmfile(gfPath) if err != nil { errors.SetError(err) return } list, err := getDepList(ctx, target, setting.WorkDir, setting.DefaultVendor) if err != nil { errors.SetError(err) return } for _, name := range list { // Check if user has specified the version. if val := gf.MustValue("deps", name); len(val) == 0 { gf.SetValue("deps", name, "") } } // Check resources. if _, err = gf.GetValue("res", "include"); err != nil { resList := make([]string, 0, len(setting.CommonRes)) for _, res := range setting.CommonRes { if base.IsExist(res) { resList = append(resList, res) } } gf.SetValue("res", "include", strings.Join(resList, "|")) } if err = setting.SaveGopmfile(gf, gfPath); err != nil { errors.SetError(err) return } if ctx.Bool("local") { localGopath := gf.MustValue("project", "local_gopath") if len(localGopath) == 0 { localGopath = "./vendor" gf.SetValue("project", "local_gopath", localGopath) if err = setting.SaveGopmfile(gf, gfPath); err != nil { errors.SetError(err) return } } for _, name := range []string{"src", "pkg", "bin"} { os.MkdirAll(path.Join(localGopath, name), os.ModePerm) } } log.Info("Generate gopmfile successfully!") }