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 }
// setup initializes and checks common environment variables. func setup(ctx *cli.Context) (err error) { setting.Debug = ctx.GlobalBool("debug") log.NonColor = ctx.GlobalBool("noterm") log.Verbose = ctx.Bool("verbose") log.Info("App Version: %s", ctx.App.Version) setting.HomeDir, err = base.HomeDir() if err != nil { return fmt.Errorf("Fail to get home directory: %v", err) } setting.HomeDir = strings.Replace(setting.HomeDir, "\\", "/", -1) setting.InstallRepoPath = path.Join(setting.HomeDir, ".gopm/repos") if runtime.GOOS == "windows" { setting.IsWindows = true } os.MkdirAll(setting.InstallRepoPath, os.ModePerm) log.Info("Local repository path: %s", setting.InstallRepoPath) if !setting.LibraryMode || len(setting.WorkDir) == 0 { setting.WorkDir, err = os.Getwd() if err != nil { return fmt.Errorf("Fail to get work directory: %v", err) } setting.WorkDir = strings.Replace(setting.WorkDir, "\\", "/", -1) } setting.DefaultVendor = path.Join(setting.WorkDir, setting.VENDOR) setting.DefaultVendorSrc = path.Join(setting.DefaultVendor, "src") if !ctx.Bool("remote") { if ctx.Bool("local") { // gf, _, _, err := genGopmfile(ctx) // if err != nil { // return err // } // setting.InstallGopath = gf.MustValue("project", "local_gopath") // if ctx.Command.Name != "gen" { // if com.IsDir(setting.InstallGopath) { // log.Log("Indicated local GOPATH: %s", setting.InstallGopath) // setting.InstallGopath += "/src" // } else { // if setting.LibraryMode { // return fmt.Errorf("Local GOPATH does not exist or is not a directory: %s", // setting.InstallGopath) // } // log.Error("", "Invalid local GOPATH path") // log.Error("", "Local GOPATH does not exist or is not a directory:") // log.Error("", "\t"+setting.InstallGopath) // log.Help("Try 'go help gopath' to get more information") // } // } } else { // Get GOPATH. setting.InstallGopath = base.GetGOPATHs()[0] if base.IsDir(setting.InstallGopath) { log.Info("Indicated GOPATH: %s", setting.InstallGopath) setting.InstallGopath += "/src" setting.HasGOPATHSetting = true } else { if ctx.Bool("gopath") { return fmt.Errorf("Local GOPATH does not exist or is not a directory: %s", setting.InstallGopath) } else { // It's OK that no GOPATH setting // when user does not specify to use. log.Warn("No GOPATH setting available") } } } } setting.ConfigFile = path.Join(setting.HomeDir, ".gopm/data/gopm.ini") if err = setting.LoadConfig(); err != nil { return err } setting.PkgNameListFile = path.Join(setting.HomeDir, ".gopm/data/pkgname.list") if err = setting.LoadPkgNameList(); err != nil { return err } setting.LocalNodesFile = path.Join(setting.HomeDir, ".gopm/data/localnodes.list") if err = setting.LoadLocalNodes(); err != nil { return err } return nil }