git clone deps

This commit is contained in:
Jeff Carr 2024-03-09 09:23:04 -06:00
parent 581a4d96fc
commit e6be71a33c
2 changed files with 32 additions and 10 deletions

36
main.go
View File

@ -4,10 +4,12 @@ import (
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"go.wit.com/dev/alexflint/arg" "go.wit.com/dev/alexflint/arg"
"go.wit.com/gui" "go.wit.com/gui"
"go.wit.com/lib/gui/repolist" "go.wit.com/lib/gui/repolist"
"go.wit.com/lib/gui/repostatus"
"go.wit.com/lib/gui/shell" "go.wit.com/lib/gui/shell"
"go.wit.com/log" "go.wit.com/log"
) )
@ -51,10 +53,23 @@ func main() {
newr.Status.MakeRedomod() newr.Status.MakeRedomod()
// rv.NewRepo("go.wit.com/apps/helloworld") // 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()
for gopath, version := range godep {
log.Info("git clone =", gopath, version)
rv.NewRepo(gopath)
}
for _, repo := range rv.AllRepos() { for _, repo := range rv.AllRepos() {
log.Info("found repo", repo.GoPath(), repo.Status.Path()) log.Info("found repo", repo.GoPath(), repo.Status.Path())
} }
rv.MakeGoWork()
// rv.Watchdog(func() { // rv.Watchdog(func() {
// log.Info("watchdog") // log.Info("watchdog")
@ -76,26 +91,31 @@ func findWorkFile() (string, error) {
pwd, err := os.Getwd() pwd, err := os.Getwd()
if err == nil { if err == nil {
// Check for go.work in the current directory and then move up until root // Check for go.work in the current directory and then move up until root
pwd, err = digup(pwd) if pwd, err := digup(pwd); err == nil {
if err == nil { // found an existing go.work file
os.Chdir(pwd) os.Chdir(pwd)
return pwd, nil return pwd, nil
} }
// if the user added '--work' on the cmdline, make a work directory and init the go.work file
if myargs.Work { if myargs.Work {
pwd := filepath.Join(pwd, "work") pwd, err = os.Getwd()
shell.Mkdir(pwd) newpwd := filepath.Join(pwd, "work")
os.Chdir(pwd) shell.Mkdir(newpwd)
os.Chdir(newpwd)
if _, err := os.Stat("go.work"); err == nil { if _, err := os.Stat("go.work"); err == nil {
return pwd, nil return newpwd, nil
} }
shell.RunPath(pwd, []string{"go", "work", "init"}) shell.RunPath(newpwd, []string{"go", "work", "init"})
if shell.Exists("go.work") { if shell.Exists("go.work") {
return pwd, nil return newpwd, nil
} }
} }
} }
// there are no go.work files, resume the ~/go/src behavior from prior to golang 1.22
// this is the 'old way" and works fine for me. I use it because I like the ~/go/src directory
// because I know exactly what is in it: GO stuff & nothing else
homeDir, err := os.UserHomeDir() homeDir, err := os.UserHomeDir()
if err != nil { if err != nil {
return "", err return "", err

View File

@ -3,6 +3,7 @@ package main
import ( import (
"bufio" "bufio"
"os" "os"
"path/filepath"
"strings" "strings"
"go.wit.com/lib/gui/shell" "go.wit.com/lib/gui/shell"
@ -15,8 +16,9 @@ func addDir(d string) {
} }
} }
func readControlFile() error { func readControlFile(path string) error {
file, err := os.Open("go.work") fullname := filepath.Join(path, "go.work")
file, err := os.Open(fullname)
if err != nil { if err != nil {
return err return err
} }