package main import ( "os" "go.wit.com/lib/gui/shell" "go.wit.com/lib/protobuf/argvpb" "go.wit.com/lib/protobuf/forgepb" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" ) // var check *gitpb.Repo var configSave bool func main() { me = new(mainType) me.argv = argvpb.Autocomplete(&argv) // adds shell auto complete to go-args me.forge, _ = forgepb.Init() // figure out what directory we are running in pwd, _ := os.Getwd() check := me.forge.Repos.FindByFullPath(pwd) if check == nil { log.Info("the forge code isn't working right. couldn't figure out path:", pwd) // just run "go mod init" and "go mod tidy" var err error _, err = shell.RunVerbose([]string{"go", "mod", "init"}) if err != nil { badExit(nil, nil) } _, err = shell.RunVerbose([]string{"go", "mod", "tidy"}) if err != nil { badExit(nil, nil) } log.Info("todo: check return values here in go-mod-clean") me.argv.GoodExit("may have worked somewhat") // exits back to the shell via argv (with timing) } // deletes all the git notes if argv.Purge != nil { purgeNotes(check) // purges all the 'git notes' eraseGoMod(check) // erase the go.mod and go.sum files okExit(check, "notes gone") } if argv.Restore { // attempt to restore from ~/go/pkg/mod/ if err := restoreFromGoPkg(check); err != nil { badExit(check, err) } okExit(check, "go.mod and go.sum restored from ~/go/pkg/mod/") } if argv.Strict != nil { log.Info("Starting --strict mode") if err := doStrict(check); err != nil { badExit(check, err) } okExit(check, "go.mod seems clean") } if argv.Smart != nil { // best effort if err := doSmart(check); err != nil { // badExit(check, err) } okExit(check, "maybe it's ok") } if argv.Force { if err := doForce(check); err != nil { badExit(check, err) } } okExit(check, "go.sum seems clean") } func findPwdRepo() *gitpb.Repo { // var check *gitpb.Repo // attempt to use the working directory // this is probably what happens most of the time pwd, _ := os.Getwd() return me.forge.Repos.FindByFullPath(pwd) /* if strings.HasPrefix(pwd, me.forge.Config.ReposDir) { gopath := strings.TrimPrefix(pwd, me.forge.Config.ReposDir) gopath = strings.Trim(gopath, "/") check = me.forge.FindByGoPath(gopath) if check != nil { log.Info(check.Namespace, "was found ok in forge") return check } } log.Info("findRepo() forge could not find GO path:", pwd) return nil */ } func saveAsMetadata(repo *gitpb.Repo) error { cname := repo.GetCurrentBranchName() if repo.GetGoPrimitive() { if err := repo.AutogenSave([]string{"go.mod"}, cname, true); err != nil { return err } } else { if err := repo.AutogenSave([]string{"go.mod", "go.sum"}, cname, true); err != nil { return err } } return nil }