diff options
| -rw-r--r-- | argv.go | 55 | ||||
| -rw-r--r-- | doDev.go | 38 | ||||
| -rw-r--r-- | doGenerate.go | 64 | ||||
| -rw-r--r-- | doShow.go | 2 | ||||
| -rw-r--r-- | errors.go | 2 | ||||
| -rw-r--r-- | main.go | 4 | ||||
| -rw-r--r-- | resources/generate | 22 |
7 files changed, 123 insertions, 64 deletions
@@ -19,25 +19,26 @@ import ( var argv args type args struct { - Clean *CleanCmd `arg:"subcommand:clean" help:"'git clean' + reset repos to original state"` - Commit *CommitCmd `arg:"subcommand:commit" help:"'git commit'"` - Gui *EmptyCmd `arg:"subcommand:gui" help:"open the gui"` - Merge *MergeCmd `arg:"subcommand:merge" help:"merge branches"` - Normal *ModeCmd `arg:"subcommand:normal" help:"shortcut to 'forge mode normal'"` - Mode *ModeCmd `arg:"subcommand:mode" help:"sets the mode (hacking, merging, publishing)"` - Patch *PatchCmd `arg:"subcommand:patch" help:"work with patchsets"` - Pull *PullCmd `arg:"subcommand:pull" help:"'git pull'"` - Show *ShowCmd `arg:"subcommand:show" help:"print out things"` - Dev *DevCmd `arg:"subcommand:dev" help:"features under development"` - Add *EmptyCmd `arg:"subcommand:add" help:"Scan directores for git repos"` - Fixer *FixCmd `arg:"subcommand:fixer" help:"send in the fixer"` - Verify *VerifyCmd `arg:"subcommand:verify" help:"populate stats"` - Whatchanged *EmptyCmd `arg:"subcommand:whatchanged" help:"being deprecated (perhaps?). this is just for finger memory."` - Rebuild *RebuildCmd `arg:"subcommand:rebuild" help:"download all the forge sources and rebuild forge"` - All bool `arg:"--all" help:"whatever you are doing, do it all over"` - Force bool `arg:"--force" help:"try to strong-arm things"` - Verbose bool `arg:"--verbose" help:"show more output than usual"` - Fix bool `arg:"--fix" help:"try to make repairs"` + Clean *CleanCmd `arg:"subcommand:clean" help:"'git clean' + reset repos to original state"` + Commit *CommitCmd `arg:"subcommand:commit" help:"'git commit'"` + Gui *EmptyCmd `arg:"subcommand:gui" help:"open the gui"` + Merge *MergeCmd `arg:"subcommand:merge" help:"merge branches"` + Normal *ModeCmd `arg:"subcommand:normal" help:"shortcut to 'forge mode normal'"` + Mode *ModeCmd `arg:"subcommand:mode" help:"sets the mode (hacking, merging, publishing)"` + Patch *PatchCmd `arg:"subcommand:patch" help:"work with patchsets"` + Pull *PullCmd `arg:"subcommand:pull" help:"'git pull'"` + Show *ShowCmd `arg:"subcommand:show" help:"print out things"` + Dev *DevCmd `arg:"subcommand:dev" help:"features under development"` + Add *EmptyCmd `arg:"subcommand:add" help:"Scan directores for git repos"` + Fixer *FixCmd `arg:"subcommand:fixer" help:"send in the fixer"` + Verify *VerifyCmd `arg:"subcommand:verify" help:"populate stats"` + Whatchanged *EmptyCmd `arg:"subcommand:whatchanged" help:"being deprecated (perhaps?). this is just for finger memory."` + Rebuild *RebuildCmd `arg:"subcommand:rebuild" help:"download all the forge sources and rebuild forge"` + Generate *GenerateCmd `arg:"subcommand:generate" help:"helps run autogenpb in repos with .proto files"` + All bool `arg:"--all" help:"whatever you are doing, do it all over"` + Force bool `arg:"--force" help:"try to strong-arm things"` + Verbose bool `arg:"--verbose" help:"show more output than usual"` + Fix bool `arg:"--fix" help:"try to make repairs"` } type EmptyCmd struct { @@ -107,11 +108,15 @@ type CommitCmd struct { } type DevCmd struct { - Config *ConfigCmd `arg:"subcommand:config" help:"show your .config/forge/ settings"` - Build *EmptyCmd `arg:"subcommand:build" help:"build this repo"` - Install *EmptyCmd `arg:"subcommand:install" help:"build & install this repo"` - Generate string `arg:"--generate" help:"run go generate"` - URL string `arg:"--connect" help:"forge url"` + Config *ConfigCmd `arg:"subcommand:config" help:"show your .config/forge/ settings"` + Build *EmptyCmd `arg:"subcommand:build" help:"build this repo"` + Install *EmptyCmd `arg:"subcommand:install" help:"build & install this repo"` + URL string `arg:"--connect" help:"forge url"` +} + +type GenerateCmd struct { + Make *EmptyCmd `arg:"subcommand:make" help:"make all the autogenerated files"` + Clean *EmptyCmd `arg:"subcommand:clean" help:"clean out all the autogenerated files"` } type CleanCmd struct { @@ -243,7 +248,7 @@ func (args) Examples() string { func (a args) SendCompletionStrings(pb *argvpb.Argv) { if pb.Cmd == "" { // these are base autocomplete strings - matches := []string{"clean", "commit", "merge", "patch", "normal", "pull", "rebuild"} + matches := []string{"clean", "commit", "merge", "patch", "normal", "pull", "rebuild", "generate"} matches = append(matches, "show", "add", "fixer", "dev", "verify", "mode", "gui", "whatchanged") matches = append(matches, "--version", "--force", "--all") pb.SendStrings(matches) @@ -3,46 +3,8 @@ package main -import ( - "errors" - "fmt" - "os" - "path/filepath" - - "go.wit.com/lib/gui/shell" - "go.wit.com/lib/protobuf/gitpb" - "go.wit.com/log" -) - -var ErrorNeedArgvFix error = errors.New("add --fix") - -func smartAutogen(repo *gitpb.Repo) error { - os.Chdir(repo.FullPath) - - globPattern := "*.proto" - files, err := filepath.Glob(globPattern) - if err != nil { - log.Info("glob error", err, files) - } - for _, filename := range files { - cmd := []string{"autogenpb", "--proto", filename} - shell.RunVerbose(cmd) - } - return err -} - // so don't delete them func doDev() (string, error) { - if argv.Dev.Generate != "" { - // helps run 'go generate' in a particular repo - found := me.forge.Repos.FindByNamespace(argv.Dev.Generate) - if found == nil { - return "", fmt.Errorf("unknown namespace %s", argv.Dev.Generate) - } - err := smartAutogen(found) - return "autogen *.proto", err - } - if argv.Dev.Install != nil { if err := doInstall(); err != nil { return "install failed", err diff --git a/doGenerate.go b/doGenerate.go new file mode 100644 index 0000000..794a26c --- /dev/null +++ b/doGenerate.go @@ -0,0 +1,64 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 + +package main + +import ( + "errors" + "fmt" + "os" + "path/filepath" + "strings" + + "go.wit.com/lib/gui/shell" + "go.wit.com/lib/protobuf/gitpb" + "go.wit.com/log" +) + +func smartAutogen(repo *gitpb.Repo) error { + os.Chdir(repo.FullPath) + + globPattern := "*.proto" + files, err := filepath.Glob(globPattern) + if err != nil { + log.Info("glob error", err, files) + } + for _, filename := range files { + cmd := []string{"autogenpb", "--proto", filename} + shell.RunVerbose(cmd) + } + return err +} + +// so don't delete them +func doGenerate() (string, error) { + // var s string + // var err error + + if argv.Generate.Make != nil { + pfile, _ := resources.ReadFile("resources/generate") + for _, namespace := range strings.Split(string(pfile), "\n") { + namespace = strings.TrimSpace(namespace) + if namespace == "" { + continue + } + if strings.HasPrefix(namespace, "#") { + continue + } + log.Info("LINE:", namespace) + + // helps run 'go generate' in a particular repo + found := me.forge.Repos.FindByNamespace(namespace) + if found == nil { + return "", fmt.Errorf("unknown namespace %s", namespace) + } + err := smartAutogen(found) + if err != nil { + return "autogen failed: " + namespace, err + } + } + return "generate worked", nil + } + + return "generate didn't run", errors.New("no subcommand chosen") +} @@ -37,7 +37,7 @@ func doShow() (string, error) { found := findRepos() if showUrls() { found.SortNamespace() - footer := me.forge.PrintForgedTable(found) + footer := found.PrintForgedTable() return "repos with patches or unsaved changes: " + footer, nil } @@ -15,3 +15,5 @@ var ErrorNoUserBranch error = errors.New("no user branch") var ErrorNoDevelBranch error = errors.New("no devel branch") var ErrorNoMasterBranch error = errors.New("no master branch") var ErrorLocalBehindDevel error = errors.New("local behind devel") + +var ErrorNeedArgvFix error = errors.New("add --fix") @@ -142,6 +142,10 @@ func main() { s, err = doPatch() } + if argv.Generate != nil { + s, err = doGenerate() + } + if argv.Whatchanged != nil { // this might be deprecated by the git devs // I put it here because of finger memory and it's nice diff --git a/resources/generate b/resources/generate new file mode 100644 index 0000000..dad3abd --- /dev/null +++ b/resources/generate @@ -0,0 +1,22 @@ +# this is a complete list of the +# WIT Private Cloud repos that +# need autogenerate run in them +# forge uses this to clean +# and redo them +# TODO: have forge just find them + +go.wit.com/apps/utils/fixup +go.wit.com/apps/utils/startxplacement +go.wit.com/lib/config +go.wit.com/lib/daemons/gus +go.wit.com/lib/protobuf/argvpb +go.wit.com/lib/protobuf/bugpb +go.wit.com/lib/protobuf/chatpb +go.wit.com/lib/protobuf/filepb +go.wit.com/lib/protobuf/forgepb +go.wit.com/lib/protobuf/gitpb +go.wit.com/lib/protobuf/guipb +go.wit.com/lib/protobuf/httppb +go.wit.com/lib/protobuf/virtpb +go.wit.com/lib/protobuf/zoopb +go.wit.com/toolkits/tree |
