summaryrefslogtreecommitdiff
path: root/main.go
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2024-11-15 13:25:52 -0600
committerJeff Carr <[email protected]>2024-11-15 13:25:52 -0600
commit2d842440365cf128b456d4a4e59433eb28e8f1ea (patch)
tree66bac9f4d8493eda7c5518004a77286f30fe0f2f /main.go
parent28bf6a27f9df6128a8f70917ca21d05cedbfb135 (diff)
argv logic handling was bungled
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'main.go')
-rw-r--r--main.go125
1 files changed, 76 insertions, 49 deletions
diff --git a/main.go b/main.go
index 4329e0f..a3460dc 100644
--- a/main.go
+++ b/main.go
@@ -29,7 +29,7 @@ func main() {
os.Exit(0)
}
- // figures out where you're go.work file is
+ // use ~/go/src unless we find a go.work file in a parent directory
wdir, err := findWorkFile()
if err != nil {
log.Info(err)
@@ -40,22 +40,70 @@ func main() {
}
- fullgitdir := filepath.Join(wdir, argv.Repo, ".git")
- if shell.IsDir(fullgitdir) {
- if ! argv.Recursive {
- log.Info("repo already cloned", filepath.Join(wdir, argv.Repo))
+ if argv.Repo == "" {
+ // if there isn't anything else, just exit here
+ // if --git-pull, continue
+ if argv.Pull || argv.RedoGoMod {
+ // there is more to do
+ log.Info("onward and upward")
+ } else {
+ // user needs to pick something to do
+ pp.WriteHelp(os.Stdout)
+ log.Info("give me something to do!")
os.Exit(0)
}
+ } else {
+ // the user specified a repo, check if it's already cloned
+ fullgitdir := filepath.Join(wdir, argv.Repo, ".git")
+ if shell.IsDir(fullgitdir) {
+ // if --recursive, continue
+ // if --git-pull, continue
+ if argv.Recursive || argv.Pull || argv.RedoGoMod {
+ log.Info("repo already cloned", filepath.Join(wdir, argv.Repo))
+ // there is more to do
+ log.Info("onward and upward")
+ } else {
+ log.Info("repo already cloned", filepath.Join(wdir, argv.Repo))
+ os.Exit(0)
+ }
+ } else {
+ // need to download this new repo!
+ log.Info("repo is new. going to clone it to:", filepath.Join(wdir, argv.Repo))
+ }
}
- // readControlFile()
-
+ // sets up gui stuff. not working yet
b := gui.RawBox()
rv = repolist.AutotypistView(b)
+ // if the user defined a repo, attempt to download it now
+ if argv.Repo != "" {
+ os.Setenv("REPO_AUTO_CLONE", "true")
+ newr, err := rv.NewRepo(argv.Repo)
+ if err != nil {
+ log.Info("could not download:", err)
+ os.Exit(-1)
+ }
+
+ // update go.sum and go.mod
+ // todo: only do this if they don't exist?
+ // todo: make these git commit metadata
+ newr.Status.MakeRedomod()
+
+ // double check it actually downloaded
+ fullgitdir := filepath.Join(wdir, argv.Repo, ".git")
+ if !shell.IsDir(fullgitdir) {
+ log.Info("repo cloned failed", filepath.Join(wdir, argv.Repo))
+ os.Exit(-1)
+ }
+ }
+
+ // look recursively in your working directory for git repos
+ totalcount := scanForRepos(wdir)
+
+ // if --git-pull, run git pull on everything here
if argv.Pull {
- count := scanForRepos(wdir)
- log.Info("Total repositories:", count)
+ log.Info("Total repositories:", totalcount)
log.Info("Going to run git pull in each one")
log.Sleep(1)
pull := []string{"git", "pull"}
@@ -75,64 +123,40 @@ func main() {
}
}
}
- log.Info("Total repositories:", count, "Total attempted:", trycount, "Errors:", errcount)
+ log.Info("Total repositories:", totalcount, "Total attempted:", trycount, "Errors:", errcount)
os.Exit(0)
}
- // if the user didn't provide a repo, stop here unless --git-pull
- if argv.Repo == "" || argv.Pull {
- pp.WriteHelp(os.Stdout)
- os.Exit(0)
- }
-
- os.Setenv("REPO_AUTO_CLONE", "true")
- newr, err := rv.NewRepo(argv.Repo)
- if err != nil {
- log.Info("could not download:", err)
- os.Exit(-1)
- }
- newr.Status.MakeRedomod()
-
- fullgitdir = filepath.Join(wdir, argv.Repo, ".git")
- if ! shell.IsDir(fullgitdir) {
- log.Info("repo cloned failed", filepath.Join(wdir, argv.Repo))
- os.Exit(-1)
- }
-
- log.Info("scanning for repo in:", filepath.Join(wdir, argv.Repo))
-
- // rv.NewRepo("go.wit.com/apps/helloworld")
- for _, path := range repostatus.ScanGitDirectories(wdir) {
- gopath := strings.TrimPrefix(path, wdir)
- gopath = strings.Trim(gopath, "/")
- // log.Info("Also should add:", gopath)
- rv.NewRepo(gopath)
- }
-
- godep := newr.Status.GetGoDeps()
+ // this is experiemental but works for me
if argv.Recursive {
+ newr := rv.FindRepoByName(argv.Repo)
+ if newr == nil {
+ log.Info("how did this repo still not exist?", argv.Repo)
+ os.Exit(-1)
+ }
+ godep := newr.Status.GetGoDeps()
for gopath, version := range godep {
repo, err := rv.NewRepo(gopath)
if err != nil {
log.Info("git clone failed for", gopath, version)
continue
}
+ // always do this for now. probably always forever
repo.Status.MakeRedomod()
}
}
- var count int
- loop := rv.ReposSortByName()
- for loop.Scan() {
- repo := loop.Repo()
- count += 1
- if !repo.Status.Exists("go.mod") {
+ // remake all the go.sum & go.mod in every repo
+ // todo: make go.sum and go.mod git commit metadata
+ if argv.RedoGoMod {
+ loop := rv.ReposSortByName()
+ for loop.Scan() {
+ repo := loop.Repo()
repo.Status.MakeRedomod()
}
}
- log.Info("Total repositories:", count)
- log.Info("Finished go-clone for", argv.Repo)
+ // remake the go.work file
if argv.AutoWork {
log.Info("About to re-create", wdir+"/go.work")
log.Info("Sleep 3. original go.work saved as go.work.last (hit ctrl-c to cancel)")
@@ -144,6 +168,9 @@ func main() {
log.Info("original go.work file saved as go.work.last")
log.Info("")
}
+
+ log.Info("Total repositories:", totalcount)
+ log.Info("Finished go-clone for", argv.Repo)
}
// look for a go.work file