diff options
| -rw-r--r-- | argv.custom.go | 103 | ||||
| -rw-r--r-- | argv.struct.go (renamed from argv.go) | 92 | ||||
| -rw-r--r-- | argv.template.go | 74 | ||||
| -rw-r--r-- | exit.go | 4 | ||||
| -rw-r--r-- | main.go | 7 | ||||
| -rw-r--r-- | structs.go | 2 |
6 files changed, 180 insertions, 102 deletions
diff --git a/argv.custom.go b/argv.custom.go new file mode 100644 index 0000000..5913868 --- /dev/null +++ b/argv.custom.go @@ -0,0 +1,103 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 + +package main + +import ( + "os" + + "go.wit.com/gui" + "go.wit.com/lib/debugger" + "go.wit.com/lib/fhelp" + "go.wit.com/lib/protobuf/argvpb" +) + +// sent via -ldflags // is there a better way? +var VERSION string +var BUILDTIME string + +// used for shell auto completion +var APPNAME string = "forge" + +func (args) Buildtime() (string, string) { + return BUILDTIME, VERSION +} + +func (a args) Description() string { + // doHelp() + + return ` +forge -- a tool to manage lots of git repos. forge includes a GUI and TUI. + + forge only executes the 'git' command. Everything it does, you can run by hand with 'git'. + + Orginally written to maintain the +50 GO git repositories for the WIT Private Cloud +` +} + +func ifBlank(arg string) bool { + if arg == "''" { + // if empty, the user has not typed something + return true + } + return false +} + +func (args) Appname() string { + return APPNAME +} + +// arg.Register(&argGui) +// log.Info("ArgvGui() started") +func (args) ArgvGui() error { + me.myGui = fhelp.Gui() // adds the GUI package argv support + me.origGui = gui.New() + return nil +} + +func (args) ArgvDebugger() bool { + debugger.InitDebugger() + // me.myGui = gui.Init() + return true +} + +func (args) Examples() string { + var out string + out += "forge show # show the state of all your repos\n" + out += "forge normal # the defaults for 'normal' forge distributed development\n" + out += " # it will makes a user branch in every git repo\n" + out += "forge clean # removes changes forge might have made\n" + out += " # purges all untracked git files, etc\n" + out += "forge pull --force # 'git pull' on all repos\n" + out += "forge commit --al # 'git commit' in every dirty repo\n" + out += "forge merge --all # 'git merge' all patches to devel & master\n" + out += "forge add # scan your current directory for all git repos\n" + return out +} + +func (args) Version() string { + // log.Info(me.sh.Version()) + // return APPNAME + " " + VERSION + " Built on " + BUILDTIME + return argvpb.StandardVersion(APPNAME, VERSION, BUILDTIME) +} + +// matches +func (c CleanCmd) Match(partial string) []string { + // return repos here + return []string{"go.wit.com/apps/forge", "go.wit.com/apps/virtigo"} +} + +// sends the strings to bash or zsh that will be your options +func (a args) SendCompletionStrings(pb *argvpb.Argv) { + if pb.Cmd == "" { + // these are base autocomplete strings + 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) + } else { + // autogenerate the strings for the subcommand using github.com/alexflint/go-arg + pb.GenerateSubCommandStrings(pb.Goargs...) + } + os.Exit(0) +} @@ -3,15 +3,6 @@ package main -import ( - "os" - - "go.wit.com/gui" - "go.wit.com/lib/debugger" - "go.wit.com/lib/fhelp" - "go.wit.com/lib/protobuf/argvpb" -) - /* this parses the command line arguements using alex flint's go-arg */ @@ -125,12 +116,6 @@ type CleanCmd struct { List *EmptyCmd `arg:"subcommand:list" help:"list not clean repos"` } -// matches -func (c CleanCmd) Match(partial string) []string { - // return repos here - return []string{"go.wit.com/apps/forge", "go.wit.com/apps/virtigo"} -} - type CleanDevelCmd struct { Force bool `arg:"--force" help:"try to strong arm things"` } @@ -183,80 +168,3 @@ type ConfigAddCmd struct { Devel string `arg:"--devel" help:"the git devel branch name"` User string `arg:"--user" help:"the git user branch name"` } - -func (args) Buildtime() (string, string) { - return BUILDTIME, VERSION -} - -func (a args) Description() string { - // doHelp() - - return ` -forge -- a tool to manage lots of git repos. forge includes a GUI and TUI. - - forge only executes the 'git' command. Everything it does, you can run by hand with 'git'. - - Orginally written to maintain the +50 GO git repositories for the WIT Private Cloud -` -} - -func ifBlank(arg string) bool { - if arg == "''" { - // if empty, the user has not typed something - return true - } - return false -} - -func (args) Appname() string { - return ARGNAME -} - -// arg.Register(&argGui) -// log.Info("ArgvGui() started") -func (args) ArgvGui() error { - me.myGui = fhelp.Gui() // adds the GUI package argv support - me.origGui = gui.New() - return nil -} - -func (args) ArgvDebugger() bool { - debugger.InitDebugger() - // me.myGui = gui.Init() - return true -} - -func (args) Examples() string { - var out string - out += "forge show # show the state of all your repos\n" - out += "forge normal # the defaults for 'normal' forge distributed development\n" - out += " # it will makes a user branch in every git repo\n" - out += "forge clean # removes changes forge might have made\n" - out += " # purges all untracked git files, etc\n" - out += "forge pull --force # 'git pull' on all repos\n" - out += "forge commit --al # 'git commit' in every dirty repo\n" - out += "forge merge --all # 'git merge' all patches to devel & master\n" - out += "forge add # scan your current directory for all git repos\n" - return out -} - -func (args) Version() string { - // log.Info(me.sh.Version()) - // return ARGNAME + " " + VERSION + " Built on " + BUILDTIME - return argvpb.StandardVersion(ARGNAME, VERSION, BUILDTIME) -} - -// sends the strings to bash or zsh that will be your options -func (a args) SendCompletionStrings(pb *argvpb.Argv) { - if pb.Cmd == "" { - // these are base autocomplete strings - 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) - } else { - // autogenerate the strings for the subcommand using github.com/alexflint/go-arg - pb.GenerateSubCommandStrings(pb.Goargs...) - } - os.Exit(0) -} diff --git a/argv.template.go b/argv.template.go new file mode 100644 index 0000000..9eefbd2 --- /dev/null +++ b/argv.template.go @@ -0,0 +1,74 @@ +package main + +// these are stubbed in functions needed +// just copy this file from another working app for now +// you shouldn't need to change anything here +// TODO: clean this up in argv + +import ( + "os" + + "go.wit.com/dev/alexflint/arg" + "go.wit.com/gui" + "go.wit.com/lib/fhelp" + "go.wit.com/log" +) + +func (args) InitArgv() (string, string, string) { + return APPNAME, BUILDTIME, VERSION +} + +// this function will send the current argv PB to go-args for parsing +func (args) ParseFlags(flags []string) error { + var err error + if me.pp == nil { + // log.Info("Parse Flags GOT flags:", flags) + me.pp, err = arg.ParseFlags(flags, &argv) + // panic("got to the app's ParseFlags()") + } else { + panic("me.pp was not nil") + } + return err +} + +// this will print the help for the subcmd +func (args) WriteHelpForAutocomplete(part string, subcmd ...string) error { + return me.pp.WriteHelpForAutocomplete(os.Stderr, os.Stdout, part, subcmd...) +} + +func (args) WriteHelpForAutocompleteDebug(part string, subcmd ...string) error { + f, _ := os.OpenFile("/tmp/argv.junk", os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + return me.pp.WriteHelpForAutocomplete(f, os.Stdout, part, subcmd...) +} + +// add this funcgion: this will print the help +func (args) WriteHelp() error { + me.pp.WriteHelp(os.Stderr) + return nil +} + +func (args) InitGui() error { + // panic("got here") + arg.Register(&gui.ArgvGui) + // me.gui = gui.PreInit() + me.myGui = fhelp.Gui() + return nil +} + +func (args) Exit() { + gui.UnloadToolkits() + if argv.Verbose { + log.Info("argv.Exit() called", APPNAME+".Exit()") + } + // remove this from the template for your app (or make one for youself if you need it) + forgeExit() // custom forge shutdown function +} + +func (args) Help() string { + return "got app help" +} + +func (args) MustParse() error { + me.pp = arg.MustParse(&argv) + return nil +} @@ -4,7 +4,6 @@ package main import ( - "go.wit.com/gui" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" ) @@ -12,8 +11,7 @@ import ( // callback for bash autocomplete to shutdown // forge properly before exiting back to the shell // hopefully will allow the GUI plugins to unload properly -func (args) Exit() { - gui.UnloadToolkits() +func forgeExit() { resetTerminalTitle() if argv.Verbose { log.Info("argv.Exit() got to forge.Exit()") @@ -14,18 +14,11 @@ import ( "go.wit.com/log" ) -// sent via -ldflags // is there a better way? -var VERSION string -var BUILDTIME string - // at build time, this can be used to store GUI plugins with matching GO deps // //go:embed resources/* var resources embed.FS -// used for shell auto completion -var ARGNAME string = "forge" - func main() { me = new(mainType) var s string @@ -4,6 +4,7 @@ package main import ( + "go.wit.com/dev/alexflint/arg" "go.wit.com/gui" "go.wit.com/lib/fhelp" "go.wit.com/lib/gadgets" @@ -31,6 +32,7 @@ func myServer() string { // this app's variables type mainType struct { sh *argvpb.Argv // shell autocomplete + pp *arg.Parser // the go-arg parser of the command line forge *forgepb.Forge // for holding the forge protobuf files myGui *fhelp.GuiPrep // for initializing the GUI toolkits origGui *gui.Node // for initializing the GUI toolkits |
