forgeConfig code merged here

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2025-01-06 21:02:04 -06:00
parent 38c0ec7caa
commit be98039d69
1 changed files with 44 additions and 0 deletions

View File

@ -1,6 +1,9 @@
package main
import (
"os"
"go.wit.com/lib/protobuf/forgepb"
"go.wit.com/log"
)
@ -23,6 +26,47 @@ func doConfig() {
}
}
// try to add, then save config and exit
if argv.Config.Add != nil {
log.Info("going to add a new repo", argv.Config.Add.GoPath)
deleteGoPath(me.forge, argv.Config.Add.GoPath)
new1 := forgepb.ForgeConfig{
GoPath: argv.Config.Add.GoPath,
Writable: argv.Config.Add.Writable,
ReadOnly: argv.Config.Add.ReadOnly,
Private: argv.Config.Add.Private,
Directory: argv.Config.Add.Directory,
Favorite: argv.Config.Add.Favorite,
Interesting: argv.Config.Add.Interesting,
MasterBranchName: argv.Config.Add.Master,
DevelBranchName: argv.Config.Add.Devel,
UserBranchName: argv.Config.Add.User,
}
if me.forge.Config.Append(&new1) {
log.Info("added", new1.GoPath, "ok")
} else {
log.Info("added", new1.GoPath, "failed")
os.Exit(-1)
}
me.forge.ConfigSave()
os.Exit(0)
}
me.forge.ConfigPrintTable()
okExit("")
}
func deleteGoPath(f *forgepb.Forge, gopath string) bool {
var deleted bool = false
for {
if f.Config.DeleteByGoPath(gopath) {
log.Info("deleted ok", gopath)
deleted = true
} else {
log.Info("did not delete", gopath)
break
}
}
return deleted
}