refactor to use forgepb

This commit is contained in:
Jeff Carr 2024-11-30 01:35:56 -06:00
parent fbab336c03
commit 6e5fbd4c33
2 changed files with 36 additions and 29 deletions

53
main.go
View File

@ -3,12 +3,10 @@ package main
import (
"os"
"path/filepath"
"strings"
"go.wit.com/dev/alexflint/arg"
"go.wit.com/gui"
"go.wit.com/lib/gui/repolist"
"go.wit.com/lib/gui/repostatus"
"go.wit.com/lib/gui/shell"
"go.wit.com/lib/protobuf/forgepb"
"go.wit.com/log"
@ -30,16 +28,10 @@ func main() {
os.Exit(0)
}
// use ~/go/src unless we find a go.work file in a parent directory
goSrcPath, err := forgepb.FindGoSrc()
if err != nil {
log.Info(err)
os.Exit(-1)
}
if goSrcPath != "" {
os.Setenv("REPO_WORK_PATH", goSrcPath)
}
// load the ~/.config/forge/ config
forge := forgepb.Init()
forge.ConfigPrintTable()
os.Setenv("REPO_WORK_PATH", forge.GetGoSrc())
if argv.Repo == "" {
// if there isn't anything else, just exit here
@ -76,18 +68,29 @@ func main() {
}
}
// sets up gui stuff. not working yet
b := gui.RawBox()
rv = repolist.AutotypistView(b)
// testing gui idea
myGui := gui.New()
// myGui.Default()
rv := repolist.Init(forge, myGui)
rv.Enable()
rv.ScanRepositories()
// 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)
// pb, _ := forge.NewGoPath(argv.Repo)
pb, err := forge.Clone(argv.Repo)
if err != nil {
log.Info("could not download:", err)
os.Exit(-1)
}
newr, err := rv.AddRepo(pb)
if err != nil {
log.Info("AddRepo() failed", err)
os.Exit(-1)
}
if argv.Recursive || argv.Pull || argv.RedoGoMod {
log.Info("repo already cloned", filepath.Join(goSrcPath, argv.Repo))
// there is more to do
@ -115,7 +118,7 @@ func main() {
os.Setenv("REPO_AUTO_CLONE", "false")
// look recursively in your working directory for git repos
totalcount := scanForRepos(goSrcPath)
totalcount := forge.Repos.Len()
// if --git-pull, run git pull on everything here
if argv.Pull {
@ -153,7 +156,12 @@ func main() {
os.Setenv("REPO_AUTO_CLONE", "true")
godep := newr.Status.GetGoDeps()
for gopath, version := range godep {
repo, err := rv.NewRepo(gopath)
pb, err := forge.Clone(gopath)
if err != nil {
log.Info("could not download:", err)
os.Exit(-1)
}
repo, err := rv.AddRepo(pb)
if err != nil {
log.Info("git clone failed for", gopath, version)
continue
@ -190,6 +198,7 @@ func main() {
log.Info("Finished go-clone for", argv.Repo)
}
/*
func scanForRepos(goSrcPath string) int {
var count int
log.Info("scanning for repo in:", filepath.Join(goSrcPath, argv.Repo))
@ -200,7 +209,13 @@ func scanForRepos(goSrcPath string) int {
gopath := strings.TrimPrefix(path, goSrcPath)
gopath = strings.Trim(gopath, "/")
// log.Info("Also should add:", gopath)
rv.NewRepo(gopath)
pb, err := forge.Clone(gopath)
if err != nil {
log.Info("could not download:", err)
os.Exit(-1)
}
repo, err := rv.AddRepo(pb)
}
return count
}
*/

View File

@ -1,15 +1,6 @@
package main
import (
"bufio"
"os"
"path/filepath"
"strings"
"go.wit.com/lib/gui/shell"
"go.wit.com/log"
)
/*
func addDir(d string) {
if shell.IsDir(d) {
rv.NewRepo(d)
@ -47,3 +38,4 @@ func readControlFile(path string) error {
return nil
}
*/