func save(w *workspace, args []string) { var targets []string godeps := false for _, t := range args { if t == "--godeps" { godeps = true } else { targets = append(targets, t) } } pkgs := w.getOutsidePackages(targets) addonMapping := map[string]string{} for pkg, dir := range pkgs { destination := filepath.Join(w.vendorRootSrc(), pkg) // if it's already in here, vendor will pick it up if !filepath.IsAbs(dir) { continue } if x, err := filepath.Rel(w.Root, dir); err == nil && !strings.HasPrefix(x, "..") { continue } addonMapping[destination] = dir } var addons []string for destination, dir := range addonMapping { addons = append(addons, destination+"="+dir) } var rgits, rhgs []string if godeps { for _, dd := range w.importGodeps() { rarg := dd.root + "=" + dd.repo + "@" + dd.rev switch dd.kind { case "git": rgits = append(rgits, rarg) case "hg": rhgs = append(rhgs, rarg) default: fmt.Fprintf(os.Stderr, "unsupported VCS %q\n", dd.kind) } } } ignoreDirs := []string{".git", ".hg", ".gocfg"} for _, gopath := range w.Gopaths { ignoreDirs = append(ignoreDirs, filepath.Join(gopath, "pkg"), filepath.Join(gopath, "bin")) } ignored := map[string]bool{} for _, dir := range ignoreDirs { ignored[dir] = true } cfgPath := filepath.Join(w.Root, ConfigDirName, "vendor.json") vend.Save(w.Root, cfgPath, addons, rgits, rhgs, ignored, true) }
func main() { fs := flag.NewFlagSet("vendor", flag.ExitOnError) dir := fs.String("d", ".", "directory to vendor into") save := fs.Bool("s", false, "save the repos and revisions") restore := fs.Bool("r", false, "restore the repos and revisions") version := fs.Bool("v", false, "print vendor version info") extend := fs.Bool("x", false, "extend the existing config instead of overwriting it") var args, addons, rgits, rhgs []string isMaybeSave := false var isAddon, isGit, isHg bool for _, arg := range os.Args[1:] { if isAddon { addons = append(addons, arg) isAddon = false continue } if isGit { rgits = append(rgits, arg) isGit = false continue } if isHg { rhgs = append(rhgs, arg) isHg = false continue } switch arg { case "-s": isMaybeSave = true args = append(args, arg) case "-a": if !isMaybeSave { args = append(args, arg) } else { isAddon = true } case "-rgit": if !isMaybeSave { args = append(args, arg) } else { isGit = true } case "-rhg": if !isMaybeSave { args = append(args, arg) } else { isHg = true } default: args = append(args, arg) } } ignored := map[string]bool{} ignoredStr := os.Getenv("VENDOR_IGNORE_DIRS") for _, ignore := range strings.Split(ignoredStr, string(filepath.ListSeparator)) { ignored[ignore] = true } fs.Parse(args) if *version { fmt.Println("vendor build 3") os.Exit(0) } if fs.NArg() != 1 || *save == *restore { usage() } var err error if *save { err = vend.Save(*dir, fs.Arg(0), addons, rgits, rhgs, ignored, *extend) } if *restore { err = vend.Restore(*dir, fs.Arg(0)) } if err != nil { fmt.Fprintln(os.Stderr, err) os.Exit(1) } }