From 9278157fc2a5ac8835dbc1aa505ccff9ec5f064f Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 18 Oct 2025 11:16:44 -0500 Subject: new argv support scheme --- argv.custom.go | 103 ++++++++++++++++++++++ argv.go | 262 ------------------------------------------------------- argv.struct.go | 170 ++++++++++++++++++++++++++++++++++++ argv.template.go | 74 ++++++++++++++++ exit.go | 4 +- main.go | 7 -- structs.go | 2 + 7 files changed, 350 insertions(+), 272 deletions(-) create mode 100644 argv.custom.go delete mode 100644 argv.go create mode 100644 argv.struct.go create mode 100644 argv.template.go 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) +} diff --git a/argv.go b/argv.go deleted file mode 100644 index f0a178e..0000000 --- a/argv.go +++ /dev/null @@ -1,262 +0,0 @@ -// 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" -) - -/* - this parses the command line arguements using alex flint's go-arg -*/ - -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"` - 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 { -} - -type testCmd string - -type ShowCmd struct { - Dirty *EmptyCmd `arg:"subcommand:dirty" help:"show dirty git repos"` - DirtySave *EmptyCmd `arg:"subcommand:dirtysave" help:"check dirty then save"` - MasterDefault *EmptyCmd `arg:"subcommand:masterdefault" help:"run the default behavior for master branches"` - Mtime *EmptyCmd `arg:"subcommand:mtime" help:"show mtime changes"` - Repo *RepoCmd `arg:"subcommand:repos" help:"print a table of the current repos"` - Tag *TagCmd `arg:"subcommand:tag" help:"show git tags"` -} - -type RebuildCmd struct { - Forge *EmptyCmd `arg:"subcommand:forge" help:"rebuild forge"` - GoClone *EmptyCmd `arg:"subcommand:go-clone" help:"rebuild go-clone"` - Autogenpb *EmptyCmd `arg:"subcommand:autogenpb" help:"rebuild autogenpb"` -} - -type FixCmd struct { - Porcelain *EmptyCmd `arg:"subcommand:porcelain" help:"git status --porcelain"` - Urls bool `arg:"--urls" help:"check for changes in repo urls"` - Untracked bool `arg:"--untracked" help:"git untracked file list"` - DeleteUser bool `arg:"--delete-user" help:"delete all user branches (checks for safety)"` - Prune bool `arg:"--prune" help:"'git fetch --prune' everywhere"` -} - -type VerifyCmd struct { - Namespace *EmptyCmd `arg:"subcommand:namespace" help:"check the namespaces"` - Stats *StatsCmd `arg:"subcommand:stats" help:"generate origin.pb"` - DryRun bool `arg:"--dry-run" help:"try not to change anything"` -} - -type StatsCmd struct { - All bool `arg:"--all" help:"process all stats"` - Sizes bool `arg:"--sizes" help:"show sizes"` - List bool `arg:"--list" help:"list all stats"` -} - -func (ShowCmd) Examples() string { - return "forge show dirty\nforge show repos --all" -} - -type RepoCmd struct { - Urls *EmptyCmd `arg:"subcommand:urls" help:"show repo urls"` - All bool `arg:"--all" help:"select every repo (the default)"` - Mine bool `arg:"--mine" help:"your repos as defined in the forge config"` - Favorites bool `arg:"--favorites" help:"your repos configured as favorites"` - Private bool `arg:"--private" help:"your private repos from your .config/forge/"` - User bool `arg:"--user" help:"show repos on the user branch"` - Full bool `arg:"--full" help:"show full repo names"` -} - -type ModeCmd struct { - Master *EmptyCmd `arg:"subcommand:master" help:"keep all repos on the master branch"` - Devel *EmptyCmd `arg:"subcommand:devel" help:"use devel branches"` - User *EmptyCmd `arg:"subcommand:user" help:"use user branches"` - Normal *EmptyCmd `arg:"subcommand:normal" help:"use the 'normal' forge development mode"` - Clean *EmptyCmd `arg:"subcommand:clean" help:"clean mode. removes everything to origin/HEAD"` -} - -type CommitCmd struct { - All bool `arg:"--all" help:"git commit in all dirty repos"` -} - -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"` - 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"` - Verbose bool `arg:"--verbose" help:"be verbose about it"` - Strict bool `arg:"--strict" help:"die if any namespaces are missing"` -} - -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"` -} - -type PatchCmd struct { - Apply bool `arg:"--apply" help:"attempt to apply any new patches"` - Show bool `arg:"--show" help:"show the current patches"` - Submit bool `arg:"--resubmit" help:"resubmit your git commits"` -} - -type PullCmd struct { - Force bool `arg:"--force" help:"try to strong-arm things"` - List *EmptyCmd `arg:"subcommand:list" help:"list repo versions"` - Check *RepoCmd `arg:"subcommand:check" help:"check for repo changes"` - Update *EmptyCmd `arg:"subcommand:update" help:"report updates"` -} - -type TagCmd struct { - List *EmptyCmd `arg:"subcommand:list" help:"list the tags"` - Clean *EmptyCmd `arg:"subcommand:clean" help:"clean out old and duplicate tags"` - Delete string `arg:"--delete" help:"delete a tag"` -} - -type MergeCmd struct { - All bool `arg:"--all" help:"merge all"` - Devel *EmptyCmd `arg:"subcommand:devel" help:"merge user to devel"` - Master *EmptyCmd `arg:"subcommand:master" help:"merge devel to master"` - Publish *EmptyCmd `arg:"subcommand:publish" help:"increment versions and publish master branch"` - Check *EmptyCmd `arg:"subcommand:check" help:"check if merge is complete and ready to publish"` -} - -type ConfigCmd struct { - Add *ConfigAddCmd `arg:"subcommand:add" help:"add a config setting"` - List *EmptyCmd `arg:"subcommand:list" help:"list your config settings"` - Delete string `arg:"--delete" help:"delete this repo"` - Register string `arg:"--register" help:"register your git URL (foo.com/mystuff) or (github.com/foo/bar)"` -} - -type ConfigAddCmd struct { - Path string `arg:"--path" help:"absolute path of the git repo"` - Namespace string `arg:"--namespace" help:"namespace of the git repo"` - Directory bool `arg:"--directory" help:"repo is a directory to match against"` - ReadOnly bool `arg:"--readonly" help:"repo is readonly"` - Writable bool `arg:"--writable" help:"repo is writable"` - Favorite bool `arg:"--favorite" help:"forge will always go-clone or git clone this" default:"false"` - Private bool `arg:"--private" default:"false" help:"repo can not be published"` - Interesting bool `arg:"--interesting" default:"false" help:"something you decided was cool"` - DebName string `arg:"--debname" help:"the name of the debian package (or rpm, etc)"` - Master string `arg:"--master" help:"the git 'master' or 'main' branch name"` - 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.struct.go b/argv.struct.go new file mode 100644 index 0000000..556a1cb --- /dev/null +++ b/argv.struct.go @@ -0,0 +1,170 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 + +package main + +/* + this parses the command line arguements using alex flint's go-arg +*/ + +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"` + 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 { +} + +type testCmd string + +type ShowCmd struct { + Dirty *EmptyCmd `arg:"subcommand:dirty" help:"show dirty git repos"` + DirtySave *EmptyCmd `arg:"subcommand:dirtysave" help:"check dirty then save"` + MasterDefault *EmptyCmd `arg:"subcommand:masterdefault" help:"run the default behavior for master branches"` + Mtime *EmptyCmd `arg:"subcommand:mtime" help:"show mtime changes"` + Repo *RepoCmd `arg:"subcommand:repos" help:"print a table of the current repos"` + Tag *TagCmd `arg:"subcommand:tag" help:"show git tags"` +} + +type RebuildCmd struct { + Forge *EmptyCmd `arg:"subcommand:forge" help:"rebuild forge"` + GoClone *EmptyCmd `arg:"subcommand:go-clone" help:"rebuild go-clone"` + Autogenpb *EmptyCmd `arg:"subcommand:autogenpb" help:"rebuild autogenpb"` +} + +type FixCmd struct { + Porcelain *EmptyCmd `arg:"subcommand:porcelain" help:"git status --porcelain"` + Urls bool `arg:"--urls" help:"check for changes in repo urls"` + Untracked bool `arg:"--untracked" help:"git untracked file list"` + DeleteUser bool `arg:"--delete-user" help:"delete all user branches (checks for safety)"` + Prune bool `arg:"--prune" help:"'git fetch --prune' everywhere"` +} + +type VerifyCmd struct { + Namespace *EmptyCmd `arg:"subcommand:namespace" help:"check the namespaces"` + Stats *StatsCmd `arg:"subcommand:stats" help:"generate origin.pb"` + DryRun bool `arg:"--dry-run" help:"try not to change anything"` +} + +type StatsCmd struct { + All bool `arg:"--all" help:"process all stats"` + Sizes bool `arg:"--sizes" help:"show sizes"` + List bool `arg:"--list" help:"list all stats"` +} + +func (ShowCmd) Examples() string { + return "forge show dirty\nforge show repos --all" +} + +type RepoCmd struct { + Urls *EmptyCmd `arg:"subcommand:urls" help:"show repo urls"` + All bool `arg:"--all" help:"select every repo (the default)"` + Mine bool `arg:"--mine" help:"your repos as defined in the forge config"` + Favorites bool `arg:"--favorites" help:"your repos configured as favorites"` + Private bool `arg:"--private" help:"your private repos from your .config/forge/"` + User bool `arg:"--user" help:"show repos on the user branch"` + Full bool `arg:"--full" help:"show full repo names"` +} + +type ModeCmd struct { + Master *EmptyCmd `arg:"subcommand:master" help:"keep all repos on the master branch"` + Devel *EmptyCmd `arg:"subcommand:devel" help:"use devel branches"` + User *EmptyCmd `arg:"subcommand:user" help:"use user branches"` + Normal *EmptyCmd `arg:"subcommand:normal" help:"use the 'normal' forge development mode"` + Clean *EmptyCmd `arg:"subcommand:clean" help:"clean mode. removes everything to origin/HEAD"` +} + +type CommitCmd struct { + All bool `arg:"--all" help:"git commit in all dirty repos"` +} + +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"` + 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"` + Verbose bool `arg:"--verbose" help:"be verbose about it"` + Strict bool `arg:"--strict" help:"die if any namespaces are missing"` +} + +type CleanCmd struct { + List *EmptyCmd `arg:"subcommand:list" help:"list not clean repos"` +} + +type CleanDevelCmd struct { + Force bool `arg:"--force" help:"try to strong arm things"` +} + +type PatchCmd struct { + Apply bool `arg:"--apply" help:"attempt to apply any new patches"` + Show bool `arg:"--show" help:"show the current patches"` + Submit bool `arg:"--resubmit" help:"resubmit your git commits"` +} + +type PullCmd struct { + Force bool `arg:"--force" help:"try to strong-arm things"` + List *EmptyCmd `arg:"subcommand:list" help:"list repo versions"` + Check *RepoCmd `arg:"subcommand:check" help:"check for repo changes"` + Update *EmptyCmd `arg:"subcommand:update" help:"report updates"` +} + +type TagCmd struct { + List *EmptyCmd `arg:"subcommand:list" help:"list the tags"` + Clean *EmptyCmd `arg:"subcommand:clean" help:"clean out old and duplicate tags"` + Delete string `arg:"--delete" help:"delete a tag"` +} + +type MergeCmd struct { + All bool `arg:"--all" help:"merge all"` + Devel *EmptyCmd `arg:"subcommand:devel" help:"merge user to devel"` + Master *EmptyCmd `arg:"subcommand:master" help:"merge devel to master"` + Publish *EmptyCmd `arg:"subcommand:publish" help:"increment versions and publish master branch"` + Check *EmptyCmd `arg:"subcommand:check" help:"check if merge is complete and ready to publish"` +} + +type ConfigCmd struct { + Add *ConfigAddCmd `arg:"subcommand:add" help:"add a config setting"` + List *EmptyCmd `arg:"subcommand:list" help:"list your config settings"` + Delete string `arg:"--delete" help:"delete this repo"` + Register string `arg:"--register" help:"register your git URL (foo.com/mystuff) or (github.com/foo/bar)"` +} + +type ConfigAddCmd struct { + Path string `arg:"--path" help:"absolute path of the git repo"` + Namespace string `arg:"--namespace" help:"namespace of the git repo"` + Directory bool `arg:"--directory" help:"repo is a directory to match against"` + ReadOnly bool `arg:"--readonly" help:"repo is readonly"` + Writable bool `arg:"--writable" help:"repo is writable"` + Favorite bool `arg:"--favorite" help:"forge will always go-clone or git clone this" default:"false"` + Private bool `arg:"--private" default:"false" help:"repo can not be published"` + Interesting bool `arg:"--interesting" default:"false" help:"something you decided was cool"` + DebName string `arg:"--debname" help:"the name of the debian package (or rpm, etc)"` + Master string `arg:"--master" help:"the git 'master' or 'main' branch name"` + Devel string `arg:"--devel" help:"the git devel branch name"` + User string `arg:"--user" help:"the git user branch name"` +} 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 +} diff --git a/exit.go b/exit.go index 929e9e0..aa2c87f 100644 --- a/exit.go +++ b/exit.go @@ -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()") diff --git a/main.go b/main.go index 42e3a81..d7d458a 100644 --- a/main.go +++ b/main.go @@ -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 diff --git a/structs.go b/structs.go index c1df6cb..d022e67 100644 --- a/structs.go +++ b/structs.go @@ -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 -- cgit v1.2.3