forge/main.go

188 lines
3.5 KiB
Go
Raw Normal View History

package main
// An app to submit patches for the 30 GO GUI repos
import (
2025-01-06 15:44:56 -06:00
"os"
2024-12-14 13:12:42 -06:00
"strings"
2024-12-02 06:59:56 -06:00
"go.wit.com/dev/alexflint/arg"
2024-12-24 02:26:54 -06:00
"go.wit.com/gui"
2024-12-02 06:59:56 -06:00
"go.wit.com/lib/protobuf/forgepb"
2024-12-05 12:29:47 -06:00
"go.wit.com/lib/protobuf/gitpb"
"go.wit.com/log"
)
2024-12-02 06:59:56 -06:00
// sent via -ldflags
var VERSION string
var BUILDTIME string
2024-12-13 16:17:36 -06:00
// using this for now. triggers config save
var configSave bool
2024-12-17 06:36:00 -06:00
func getVersion(repo *gitpb.Repo, name string) string {
cmd := []string{"git", "describe", "--tags", "--always", name}
result := repo.RunQuiet(cmd)
output := strings.Join(result.Stdout, "\n")
log.Info("cmd =", cmd, output)
return strings.TrimSpace(output)
}
func main() {
me = new(mainType)
2024-12-02 06:59:56 -06:00
me.pp = arg.MustParse(&argv)
2025-01-06 15:44:56 -06:00
if argv.Bash {
argv.doBash()
os.Exit(0)
}
if len(argv.BashAuto) != 0 {
argv.doBashAuto()
os.Exit(0)
}
2024-12-14 13:12:42 -06:00
me.urlbase = argv.URL
2024-12-24 03:35:19 -06:00
if me.urlbase == "" {
me.urlbase = "https://go.wit.com/"
}
2024-12-14 13:12:42 -06:00
me.urlbase = strings.Trim(me.urlbase, "/") // track down why trailing '/' makes http POST not work
2024-12-02 06:59:56 -06:00
// load the ~/.config/forge/ config
me.forge = forgepb.Init()
2024-12-05 12:29:47 -06:00
me.found = new(gitpb.Repos)
2024-12-27 03:39:53 -06:00
if argv.User != nil {
me.forge.CheckoutUser()
2024-12-27 03:39:53 -06:00
me.forge = forgepb.Init()
me.found = new(gitpb.Repos)
argv.User.findRepos()
doCobol()
okExit("")
}
2024-12-27 03:39:53 -06:00
if argv.Devel != nil {
me.forge.CheckoutDevel()
me.forge = forgepb.Init()
me.found = new(gitpb.Repos)
argv.Devel.findRepos()
doCobol()
okExit("")
}
if argv.Master != nil {
me.forge.CheckoutMaster()
2024-12-27 03:39:53 -06:00
me.forge = forgepb.Init()
me.found = new(gitpb.Repos)
argv.Master.findRepos()
doCobol()
okExit("")
}
2024-12-24 01:54:33 -06:00
if argv.Register != "" {
if err := doRegister(argv.Register); err == nil {
okExit("attempting to register " + argv.Register)
} else {
badExit(err)
}
2024-12-23 11:15:16 -06:00
}
2024-12-27 22:27:19 -06:00
if argv.Apply != "" {
pset, err := readPatchFile(argv.Apply)
if err != nil {
badExit(err)
}
2025-01-05 04:54:05 -06:00
if err = applyPatchset(pset); err == nil {
2024-12-27 22:27:19 -06:00
okExit("applied patch ok")
}
badExit(err)
}
2024-12-17 15:34:13 -06:00
if argv.Delete != "" {
me.forge.DeleteByGoPath(argv.Delete)
me.forge.SetConfigSave(true)
okExit("")
}
2024-12-17 01:14:37 -06:00
if argv.Fix {
okExit("")
}
2024-12-05 12:29:47 -06:00
// first find the repos or gopaths to operate on
2024-12-27 04:36:29 -06:00
if argv.Config != nil {
findConfig(argv.Config)
me.forge.ConfigPrintTable()
okExit("")
2024-12-02 08:44:58 -06:00
}
2024-12-05 12:29:47 -06:00
log.Info("found", me.found.Len(), "repos. found", len(me.foundPaths), "paths from .config/forge")
2024-12-05 12:29:47 -06:00
// now, do something to all of them (or just print out a table of them)
var done bool = false
2024-12-27 04:36:29 -06:00
if argv.Dirty != nil {
findAll() // select all the repos
doCheckDirtyAndConfigSave()
me.found = new(gitpb.Repos)
findDirty()
doCobol()
2024-12-25 23:17:24 -06:00
okExit("")
done = true
}
2024-12-24 03:08:06 -06:00
2024-12-25 23:17:24 -06:00
if argv.Scan {
me.forge.ScanGoSrc()
2024-12-25 23:17:24 -06:00
done = true
}
2024-02-14 13:43:43 -06:00
2024-12-27 03:39:53 -06:00
if argv.GitPull != nil {
argv.GitPull.findRepos()
2024-12-25 23:17:24 -06:00
doGitPull()
done = true
}
2024-12-25 23:17:24 -06:00
if argv.GitReset {
findAll() // select all the repos
2024-12-25 23:17:24 -06:00
doGitReset()
done = true
}
2024-12-13 17:13:07 -06:00
2024-12-27 03:39:53 -06:00
if argv.List != nil {
argv.List.findRepos()
2024-12-25 23:17:24 -06:00
// print out the repos
doCobol()
done = true
}
if argv.PatchSet != "" {
sendDevelDiff(argv.PatchSet)
// sendMasterDiff()
okExit("patches")
2024-12-13 13:17:26 -06:00
}
2024-12-14 14:09:15 -06:00
if argv.ListPatchSet {
listPatches()
okExit("patches")
}
2024-12-24 03:08:06 -06:00
if configSave {
me.forge.ConfigSave()
configSave = false
}
2024-12-24 02:26:54 -06:00
// if the user doesn't want to open the GUI and
// nothing else was specified to be done,
// then just list the table to stdout
if gui.NoGui() {
if !done {
// if nothing was selected, print out a table of them on STDOUT
doCobol()
okExit("")
}
2024-12-05 12:29:47 -06:00
}
2024-12-27 03:39:53 -06:00
// open the gui unless the user performed some other
// things from the command line
// basically, if you run just 'forge' it'll open the GUI
if !done {
doGui()
}
2024-12-17 06:36:00 -06:00
okExit("")
}