diff options
| author | Jeff Carr <[email protected]> | 2025-09-25 19:50:01 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-09-25 21:04:02 -0500 |
| commit | 192234aa6bb9e454961336729f600b6d1915968b (patch) | |
| tree | 1ffef8e19f8cfa2fa89288971a5df895da4ca81c | |
| parent | 460338c4eb00f9fa6461105794e0d1989b8c8e3c (diff) | |
redo argv
| -rw-r--r-- | argv.go | 41 | ||||
| -rw-r--r-- | doMerge.go | 135 | ||||
| -rw-r--r-- | doPatches.go (renamed from doList.go) | 19 | ||||
| -rw-r--r-- | main.go | 30 |
4 files changed, 51 insertions, 174 deletions
@@ -19,13 +19,9 @@ import ( var argv args type args struct { - Pull *EmptyCmd `arg:"subcommand:pull" help:"'git pull' on the repos"` - List *EmptyCmd `arg:"subcommand:list" help:"list the repos"` - Clean *EmptyCmd `arg:"subcommand:clean" help:"clean the repos"` + Repos *ReposCmd `arg:"subcommand:repos" help:"the forged repos"` + Patch *PatchCmd `arg:"subcommand:patches" help:"the forged patches"` Gui *EmptyCmd `arg:"subcommand:gui" help:"show gui"` - Merge *EmptyCmd `arg:"subcommand:merge" help:"merge in new patchsets"` - Init *EmptyCmd `arg:"subcommand:init" help:"init the repo list"` - Repos *EmptyCmd `arg:"subcommand:repos" help:"show the repos"` Port int `arg:"--port" default:"2520" help:"port to run on"` Hostname string `arg:"--hostname" help:"hostname to use"` Daemon bool `arg:"--daemon" help:"run as a daemon"` @@ -36,10 +32,28 @@ type args struct { type EmptyCmd struct { } +type PatchCmd struct { + List *EmptyCmd `arg:"subcommand:list" help:"list the patches"` + Clean *EmptyCmd `arg:"subcommand:clean" help:"clean the patches"` + Init *EmptyCmd `arg:"subcommand:init" help:"init"` +} + +type ReposCmd struct { + List *EmptyCmd `arg:"subcommand:list" help:"list the repos"` + Pull *EmptyCmd `arg:"subcommand:pull" help:"'git pull' on the repos"` + Clean *EmptyCmd `arg:"subcommand:clean" help:"clean the repos"` + Merge *EmptyCmd `arg:"subcommand:merge" help:"merge in new patchsets"` + Init *EmptyCmd `arg:"subcommand:init" help:"init the repo list"` +} + func (args) Appname() string { return ARGNAME } +func (args) Buildtime() (string, string) { + return BUILDTIME, VERSION +} + func (args) Version() string { parts := strings.Split(BUILDTIME, ".") if len(parts) == 1 { @@ -73,14 +87,15 @@ func (args) Version() string { return ARGNAME + " " + VERSION + " Built on " + BUILDTIME } +/* + handles shell autocomplete +*/ + func (a args) DoAutoComplete(pb *prep.Auto) { - switch pb.Cmd { - case "list": - pb.Autocomplete2("--missing") - case "clean": - pb.Autocomplete2("") - default: - pb.Autocomplete2("list clean") + if pb.Cmd == "" { + pb.Autocomplete3([]string{"--bash", "repos", "gui", "patches", "--daemon"}) + } else { + pb.SubCommand(pb.Argv...) } os.Exit(0) } diff --git a/doMerge.go b/doMerge.go deleted file mode 100644 index 9dfb6bb..0000000 --- a/doMerge.go +++ /dev/null @@ -1,135 +0,0 @@ -package main - -import ( - "fmt" - "os" - "path/filepath" - - "github.com/google/uuid" - "go.wit.com/lib/protobuf/forgepb" - "go.wit.com/log" - "google.golang.org/protobuf/proto" -) - -func doMerge() error { - mergePatchsets() - - if err := me.forge.SavePatchsets(); err != nil { - log.Warn("savePatchsets() failed", err) - return err - } - return nil -} - -func findAutoPatchset() *forgepb.Set { - for pset := range me.forge.Patchsets.IterAll() { - if pset.Name == "forge auto commit" { - return pset - break - } - } - - var fauto *forgepb.Set - log.Warn("findAutoPatchset() had to create 'forge auto commit'") - if fauto == nil { - fauto = new(forgepb.Set) - fauto.Name = "forge auto commit" - fauto.Patches = forgepb.NewPatches() - fauto.Uuid = uuid.New().String() - me.forge.Patchsets.Append(fauto) - } - return fauto -} - -// adds submitted patches not specifically assigned to a patchset -// to the generic patchset called "forge auto commit" -func addRandomPatch(patch *forgepb.Patch) error { - // ignore patch if it's already here - if findPatch(patch) { - log.Info("already found patch", patch.CommitHash, patch.Namespace) - return nil - } - fauto := findAutoPatchset() - if fauto == nil { - return log.Errorf("no default place yet") - } - newpb := proto.Clone(patch).(*forgepb.Patch) - if newpb == nil { - return log.Errorf("proto.Clone returned nil") - } - fauto.Patches.Patches = append(fauto.Patches.Patches, newpb) - return nil -} - -/* -// adds a patchset or just the patches -func addPatchset(filename string, pb *forgepb.Set) { - // if the name of the patchset is "forge auto commit" - // then just add all the patches - if pb.Name == "forge auto commit" { - author := "Author: " + pb.GitAuthorName - author += " <" + pb.GitAuthorEmail + ">" - - // author := "Author: " + os.Getenv("GIT_AUTHOR_NAME") - // author += " <" + os.Getenv("GIT_AUTHOR_EMAIL") + ">" - fmt.Println(filename, pb.Name, pb.Comment, author) - for _, patch := range pb.Patches.Patches { - // log.Info("\tnew patch:", i, patch.CommitHash, patch.Namespace) - if findPatch(patch) { - // log.Info("\talready found!!!!!!!", pset.Uuid, patch.Namespace) - } else { - log.Info("\tnew patch:", filename, pb.Name, pb.Comment, author) - addRandomPatch(patch) - } - } - return - } - - // if you got here, this patchset was submitted with a name - - // Has this patchset already been submitted? - for pset := range me.forge.Patchsets.IterAll() { - if pset.Uuid == pb.Uuid { - log.Info("ALREADY ADDED", pset.Uuid, pset.Name) - return - } - } - - // Clone() this protobuf into me.forge.Patchsets - var newpb *forgepb.Set - newpb = proto.Clone(pb).(*forgepb.Set) - if newpb != nil { - me.forge.Patchsets.Patchsets = append(me.forge.Patchsets.Patchsets, newpb) - } -} -*/ - -func mergePatchsets() { - dirname := filepath.Join(LIBDIR, "patchset/") - // Open the directory - entries, err := os.ReadDir(dirname) - if err != nil { - fmt.Printf("Error reading directory: %v\n", err) - return - } - - // Iterate through the directory entries - for _, entry := range entries { - // Check if the entry is a file and matches the *.pb pattern - if !entry.IsDir() && filepath.Ext(entry.Name()) == ".pb" { - bytes, err := os.ReadFile(filepath.Join(dirname, entry.Name())) - if err != nil { - fmt.Println(entry.Name(), err) - continue - } - var p *forgepb.Set - p = new(forgepb.Set) - err = p.Unmarshal(bytes) - if err != nil { - fmt.Println(entry.Name(), err) - continue - } - me.forge.AddPatchset(p) - } - } -} @@ -1,10 +1,29 @@ package main import ( + "go.wit.com/lib/fhelp" "go.wit.com/lib/protobuf/forgepb" "go.wit.com/log" ) +func doPatches() error { + if argv.Patch.List != nil { + log.Printf("forge.Init() %s len()=%d\n", me.forge.Config.Filename, me.forge.Repos.Len()) + fhelp.DumpENV("finit:") + me.forge.Config.DumpENV() + return doList() + } + + if argv.Patch.Clean != nil { + log.Printf("forge.Init() %s len()=%d\n", me.forge.Config.Filename, me.forge.Repos.Len()) + fhelp.DumpENV("finit:") + me.forge.Config.DumpENV() + return doClean() + } + + return nil +} + func doList() error { log.Infof("do list here. Patchsets.Len()=%d\n", me.forge.Patchsets.Len()) for pset := range me.forge.Patchsets.IterAll() { @@ -6,7 +6,6 @@ import ( "net/http" "time" - "go.wit.com/lib/fhelp" "go.wit.com/lib/gui/prep" "go.wit.com/lib/protobuf/forgepb" "go.wit.com/log" @@ -26,8 +25,8 @@ var LIBDIR string = "/var/lib/forged/" // need to deprecate this func main() { me = new(mainType) - me.myGui = prep.Gui() // prepares the GUI package for go-args - me.auto = prep.Bash3(&argv) // this line should be: prep.Bash(&argv) + me.myGui = prep.Gui() // prepares the GUI package for go-args + me.auto = prep.Bash(&argv) // this line should be: prep.Bash(&argv) me.forge = forgepb.InitByAppname(ARGNAME) @@ -36,34 +35,13 @@ func main() { badExit(err) } - if argv.List != nil { - log.Printf("forge.Init() %s len()=%d\n", me.forge.Config.Filename, me.forge.Repos.Len()) - fhelp.DumpENV("finit:") - me.forge.Config.DumpENV() - doList() - okExit("") - } - - if argv.Clean != nil { - log.Printf("forge.Init() %s len()=%d\n", me.forge.Config.Filename, me.forge.Repos.Len()) - fhelp.DumpENV("finit:") - me.forge.Config.DumpENV() - doClean() - okExit("") - } - - if argv.Merge != nil { - if err := doMerge(); err != nil { + if argv.Patch != nil { + if err := doPatches(); err == nil { badExit(err) } okExit("") } - if argv.Pull != nil { - log.Info("pull here") - okExit("") - } - if argv.Daemon == true { if argv.Gui != nil { me.myGui.Start() // loads the GUI toolkit |
