summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'main.go')
-rw-r--r--main.go58
1 files changed, 47 insertions, 11 deletions
diff --git a/main.go b/main.go
index ab4cb40..08cfbe3 100644
--- a/main.go
+++ b/main.go
@@ -22,11 +22,6 @@ var rv *repolist.RepoList
func main() {
pp := arg.MustParse(&argv)
- if argv.Repo == "" {
- pp.WriteHelp(os.Stdout)
- os.Exit(0)
- }
-
// for very new users or users unfamilar with the command line, this may help them
if argv.Repo == "version" || argv.Repo == "help" || argv.Repo == "?" {
pp.WriteHelp(os.Stdout)
@@ -47,6 +42,38 @@ func main() {
b := gui.RawBox()
rv = repolist.AutotypistView(b)
+ log.Info("got here")
+ if argv.Pull {
+ count := scanForRepos(wdir)
+ log.Info("Total repositories:", count)
+ log.Info("Going to run git pull in each one")
+ log.Sleep(1)
+ pull := []string{"git", "pull"}
+ loop := rv.ReposSortByName()
+ var trycount, errcount int
+ for loop.Scan() {
+ repo := loop.Repo()
+ if argv.DryRun {
+ log.Info("git pull --dry-run", repo.Status.Path())
+ } else {
+ trycount += 1
+ log.Info("actually run: git pull:", repo.Status.Path())
+ if err := shell.PwdRun(repo.Status.Path(), pull); err != nil {
+ log.Info("git pull error:", err)
+ errcount += 1
+ }
+ }
+ }
+ log.Info("Total repositories:", count, "Total attempted:", trycount, "Errors:", errcount)
+ os.Exit(0)
+ }
+
+ // if the user didn't provide a repo, stop here
+ if argv.Repo == "" {
+ pp.WriteHelp(os.Stdout)
+ os.Exit(0)
+ }
+
os.Setenv("REPO_AUTO_CLONE", "true")
newr, err := rv.NewRepo(argv.Repo)
if err != nil {
@@ -98,12 +125,6 @@ func main() {
rv.MakeGoWork()
shell.RunPath(wdir, []string{"go", "work", "use"})
}
-
- /*
- for _, repo := range rv.AllRepos() {
- log.Info("found repo", repo.GoPath(), repo.Status.Path())
- }
- */
}
// look for or make a go.work file
@@ -174,3 +195,18 @@ func digup(path string) (string, error) {
return "", fmt.Errorf("no go.work file found")
}
+
+func scanForRepos(wdir string) int {
+ var count int
+ log.Info("scanning for repo in:", filepath.Join(wdir, argv.Repo))
+
+ // rv.NewRepo("go.wit.com/apps/helloworld")
+ for _, path := range repostatus.ScanGitDirectories(wdir) {
+ count += 1
+ gopath := strings.TrimPrefix(path, wdir)
+ gopath = strings.Trim(gopath, "/")
+ // log.Info("Also should add:", gopath)
+ rv.NewRepo(gopath)
+ }
+ return count
+}