From 4684799ca211b13b821a51cb0b3c87e43bd95aa8 Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sun, 26 Oct 2025 08:29:43 -0500 Subject: new argv design --- argv.custom.go | 92 ---------------------------------------------- argv.go | 108 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ argv.struct.go | 108 ------------------------------------------------------ argv.template.go | 81 ---------------------------------------- complete.go | 84 ++++++++++++++++++++++++++++++++++++++++++ doBuild.debian.go | 5 ++- doBuild.go | 11 +++--- doClone.go | 3 +- doGit.go | 5 ++- doPublish.go | 13 ++++--- doUpgrade.go | 5 ++- exit.go | 7 ++-- main.go | 15 ++++---- structs.go | 2 +- subCommand.go | 17 +++++---- upgrade.go | 3 +- 16 files changed, 239 insertions(+), 320 deletions(-) delete mode 100644 argv.custom.go create mode 100644 argv.go delete mode 100644 argv.struct.go delete mode 100644 argv.template.go create mode 100644 complete.go diff --git a/argv.custom.go b/argv.custom.go deleted file mode 100644 index b2ccd4c..0000000 --- a/argv.custom.go +++ /dev/null @@ -1,92 +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 - -/* - this parses the command line arguements - this enables command line options from other packages like 'gui' and 'log' -*/ - -import ( - "os" - - "go.wit.com/lib/debugger" - "go.wit.com/lib/fhelp" - "go.wit.com/lib/gui/logsettings" - "go.wit.com/lib/protobuf/argvpb" - "go.wit.com/log" -) - -// sent via -ldflags -var VERSION string -var BUILDTIME string - -// used for shell auto completion -var APPNAME string = "wit" // todo: get this from $0 ? - -func init() { - if debugger.ArgDebug() { - log.Info("cmd line --debugger == true") - go func() { - log.Sleep(2) - debugger.DebugWindow() - }() - } - - if debugger.ArgLogger() { - log.Info("cmd line --loggger == true") - go func() { - log.Sleep(4) - logsettings.LogWindow() - logsettings.LogWindow() - }() - } -} - -func (args) Buildtime() (string, string) { - return BUILDTIME, VERSION -} - -func (args) Version() string { - return "wit-test " + VERSION + " Built on " + BUILDTIME -} - -/* - handles shell autocomplete -*/ - -func (args) Appname() string { - return APPNAME -} - -func (args) ArgvGui() error { - me.myGui = fhelp.Gui() // adds the GUI package argv support - return nil -} - -func (a args) DoAutoComplete(pb *argvpb.Argv) { - base := []string{"build", "upgrade", "git", "publish", "pb", "linux", "droplet", "test"} - base = append(base, "--version", "--force", "--all", "--dry-run") - - // add these only if installed - if _, err := fhelp.CheckCmd("zood"); err == nil { - base = append(base, "zoo") - } - if _, err := fhelp.CheckCmd("forge"); err == nil { - base = append(base, "forge") - } - if _, err := fhelp.CheckCmd("go-clone"); err == nil { - base = append(base, "go-clone") - } - if areSuperuser() { - base = append(base, "upgrade") - base = append(base, "rdate") - } - if pb.GetCmd() == "" { - pb.SendStrings(base) - } else { - pb.SubCommand(pb.Goargs...) - } - os.Exit(0) -} diff --git a/argv.go b/argv.go new file mode 100644 index 0000000..6813437 --- /dev/null +++ b/argv.go @@ -0,0 +1,108 @@ +// 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 + this enables command line options from other packages like 'gui' and 'log' +*/ + +var argv args + +type args struct { + Git *GitCmd `arg:"subcommand:git" help:"git stuff"` + Build *BuildCmd `arg:"subcommand:build" help:"build and install things"` + ListPkgs *EmptyCmd `arg:"subcommand:list" help:"list all the packages on mirrors.wit.com"` + Clone *CloneCmd `arg:"subcommand:go-clone" help:"go-clone from a gowebd repomap"` + Linux *LinuxCmd `arg:"subcommand:linux" help:"helpful linux things"` + Zoo *EmptyCmd `arg:"subcommand:zoo" help:"WIT Private Cloud info"` + PB *ProtoCmd `arg:"subcommand:pb" help:"example .pb files"` + Droplet *DropletCmd `arg:"subcommand:droplet" help:"do things on virtual machines"` + Upgrade *UpgradeCmd `arg:"subcommand:upgrade" help:"apt upgrade packages installed from mirrors.wit.com"` + Publish *PublishCmd `arg:"subcommand:publish" help:"publish packages"` + Test *TestCmd `arg:"subcommand:test" help:"test things"` + RepoMap string `arg:"--repomap" help:"location of the repomap"` + DryRun bool `arg:"--dry-run" help:"only show what would be packaged"` + Install bool `arg:"--install" help:"go install the binaries first"` + Verbose bool `arg:"--verbose" help:"be loud about it"` + Force bool `arg:"--force" help:"rebuild everything"` + All bool `arg:"--all" help:"show everything"` + Recursive bool `arg:"--recursive" help:"go-clone --recursive"` + WITCOM bool `arg:"--witcom" help:"add the GPL header"` + Max int32 `arg:"--max" help:"stop building after max builds"` +} + +type BuildCmd struct { + Debian *DebianCmd `arg:"subcommand:deb" help:"build missing .deb packages"` + MacBuild *EmptyCmd `arg:"subcommand:macos" help:"build macos packages"` + Install *DefaultCmd `arg:"subcommand:install" help:"run make install in each repo"` +} + +type ProtoCmd struct { + Identify string `arg:"--identify" help:"identify a .pb file"` +} + +type DropletCmd struct { + Trim *EmptyCmd `arg:"subcommand:trim" help:"clean out stuff and power off vm"` +} + +type TestCmd struct { + Version *EmptyCmd `arg:"subcommand:version" help:"test with cmd --version"` + Copy bool `arg:"--copy" help:"re-copy argv.template.go"` +} + +type LinuxCmd struct { + Rdate *EmptyCmd `arg:"subcommand:rdate" help:"rdate: check the time from the network"` +} + +type DebianCmd struct { + Release bool `arg:"--release" help:"use go-deb --release"` + DryRun bool `arg:"--dry-run" help:"only show what would be packaged"` + Verbose bool `arg:"--verbose" help:"be loud about it"` + Force bool `arg:"--force" help:"force devel .deb builds into /incoming"` + Priv bool `arg:"--private" help:"build private repos"` + All bool `arg:"--all" help:"build everything again"` + BuildVersion int `arg:"--buildversion" help:"the build version"` + Arch string `arg:"--arch" help:"what arch"` +} + +type CloneCmd struct { + Check *EmptyCmd `arg:"subcommand:check" help:"check urls against the repomap"` + Fix *EmptyCmd `arg:"subcommand:fix" help:"fix urls from the repomap"` + Repomap *EmptyCmd `arg:"subcommand:repomap" help:"make updated repomap"` + DryRun bool `arg:"--dry-run" help:"show what has not yet come to pass"` + Verbose bool `arg:"--verbose" help:"be loud about it"` +} + +type UpgradeCmd struct { + All bool `arg:"--all" help:"show all the packages"` + Force bool `arg:"--force" help:"force un-install and re-install each package"` +} + +type PublishCmd struct { + All bool `arg:"--all" help:"show all the packages"` + Gomod bool `arg:"--keep-gomod" help:"don't really do anything"` +} + +type DefaultCmd struct { + DryRun bool `arg:"--dry-run" help:"show what has not yet come to pass"` + Verbose bool `arg:"--verbose" help:"be loud about it"` + Force bool `arg:"--force" help:"rebuild everything"` +} + +type GitCmd struct { + Log *EmptyCmd `arg:"subcommand:log" help:"git log"` + Who *EmptyCmd `arg:"subcommand:who" help:"git who"` + Tag *EmptyCmd `arg:"subcommand:tag" help:"show tags"` + Pull *EmptyCmd `arg:"subcommand:pull" help:"pull the wit standard paths"` + Push *EmptyCmd `arg:"subcommand:push" help:"push the wit standard paths"` + Template string `arg:"--template" help:"create a new reup from a tempalte"` + Create string `arg:"--create" help:"create new repo"` + Edit string `arg:"--edit" help:"edit the subject of the last commit"` + ChopHEAD int `arg:"--chop-head-off" help:"remove the last commit (HEAD-1)"` + DeleteUntracked bool `arg:"--delete-untracked" help:"delete the untracked files"` +} + +type EmptyCmd struct { +} diff --git a/argv.struct.go b/argv.struct.go deleted file mode 100644 index 6813437..0000000 --- a/argv.struct.go +++ /dev/null @@ -1,108 +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 - -/* - this parses the command line arguements - this enables command line options from other packages like 'gui' and 'log' -*/ - -var argv args - -type args struct { - Git *GitCmd `arg:"subcommand:git" help:"git stuff"` - Build *BuildCmd `arg:"subcommand:build" help:"build and install things"` - ListPkgs *EmptyCmd `arg:"subcommand:list" help:"list all the packages on mirrors.wit.com"` - Clone *CloneCmd `arg:"subcommand:go-clone" help:"go-clone from a gowebd repomap"` - Linux *LinuxCmd `arg:"subcommand:linux" help:"helpful linux things"` - Zoo *EmptyCmd `arg:"subcommand:zoo" help:"WIT Private Cloud info"` - PB *ProtoCmd `arg:"subcommand:pb" help:"example .pb files"` - Droplet *DropletCmd `arg:"subcommand:droplet" help:"do things on virtual machines"` - Upgrade *UpgradeCmd `arg:"subcommand:upgrade" help:"apt upgrade packages installed from mirrors.wit.com"` - Publish *PublishCmd `arg:"subcommand:publish" help:"publish packages"` - Test *TestCmd `arg:"subcommand:test" help:"test things"` - RepoMap string `arg:"--repomap" help:"location of the repomap"` - DryRun bool `arg:"--dry-run" help:"only show what would be packaged"` - Install bool `arg:"--install" help:"go install the binaries first"` - Verbose bool `arg:"--verbose" help:"be loud about it"` - Force bool `arg:"--force" help:"rebuild everything"` - All bool `arg:"--all" help:"show everything"` - Recursive bool `arg:"--recursive" help:"go-clone --recursive"` - WITCOM bool `arg:"--witcom" help:"add the GPL header"` - Max int32 `arg:"--max" help:"stop building after max builds"` -} - -type BuildCmd struct { - Debian *DebianCmd `arg:"subcommand:deb" help:"build missing .deb packages"` - MacBuild *EmptyCmd `arg:"subcommand:macos" help:"build macos packages"` - Install *DefaultCmd `arg:"subcommand:install" help:"run make install in each repo"` -} - -type ProtoCmd struct { - Identify string `arg:"--identify" help:"identify a .pb file"` -} - -type DropletCmd struct { - Trim *EmptyCmd `arg:"subcommand:trim" help:"clean out stuff and power off vm"` -} - -type TestCmd struct { - Version *EmptyCmd `arg:"subcommand:version" help:"test with cmd --version"` - Copy bool `arg:"--copy" help:"re-copy argv.template.go"` -} - -type LinuxCmd struct { - Rdate *EmptyCmd `arg:"subcommand:rdate" help:"rdate: check the time from the network"` -} - -type DebianCmd struct { - Release bool `arg:"--release" help:"use go-deb --release"` - DryRun bool `arg:"--dry-run" help:"only show what would be packaged"` - Verbose bool `arg:"--verbose" help:"be loud about it"` - Force bool `arg:"--force" help:"force devel .deb builds into /incoming"` - Priv bool `arg:"--private" help:"build private repos"` - All bool `arg:"--all" help:"build everything again"` - BuildVersion int `arg:"--buildversion" help:"the build version"` - Arch string `arg:"--arch" help:"what arch"` -} - -type CloneCmd struct { - Check *EmptyCmd `arg:"subcommand:check" help:"check urls against the repomap"` - Fix *EmptyCmd `arg:"subcommand:fix" help:"fix urls from the repomap"` - Repomap *EmptyCmd `arg:"subcommand:repomap" help:"make updated repomap"` - DryRun bool `arg:"--dry-run" help:"show what has not yet come to pass"` - Verbose bool `arg:"--verbose" help:"be loud about it"` -} - -type UpgradeCmd struct { - All bool `arg:"--all" help:"show all the packages"` - Force bool `arg:"--force" help:"force un-install and re-install each package"` -} - -type PublishCmd struct { - All bool `arg:"--all" help:"show all the packages"` - Gomod bool `arg:"--keep-gomod" help:"don't really do anything"` -} - -type DefaultCmd struct { - DryRun bool `arg:"--dry-run" help:"show what has not yet come to pass"` - Verbose bool `arg:"--verbose" help:"be loud about it"` - Force bool `arg:"--force" help:"rebuild everything"` -} - -type GitCmd struct { - Log *EmptyCmd `arg:"subcommand:log" help:"git log"` - Who *EmptyCmd `arg:"subcommand:who" help:"git who"` - Tag *EmptyCmd `arg:"subcommand:tag" help:"show tags"` - Pull *EmptyCmd `arg:"subcommand:pull" help:"pull the wit standard paths"` - Push *EmptyCmd `arg:"subcommand:push" help:"push the wit standard paths"` - Template string `arg:"--template" help:"create a new reup from a tempalte"` - Create string `arg:"--create" help:"create new repo"` - Edit string `arg:"--edit" help:"edit the subject of the last commit"` - ChopHEAD int `arg:"--chop-head-off" help:"remove the last commit (HEAD-1)"` - DeleteUntracked bool `arg:"--delete-untracked" help:"delete the untracked files"` -} - -type EmptyCmd struct { -} diff --git a/argv.template.go b/argv.template.go deleted file mode 100644 index 6948afe..0000000 --- a/argv.template.go +++ /dev/null @@ -1,81 +0,0 @@ -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/env" - "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 -} - -// add this funcgion: this will print the help -func (args) WriteHelpForSubcommand(cmd string) error { - me.pp.WriteHelpForSubcommand(os.Stderr, cmd) - return nil -} - -// 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 env.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/complete.go b/complete.go new file mode 100644 index 0000000..f9165e0 --- /dev/null +++ b/complete.go @@ -0,0 +1,84 @@ +// Copyright 2017-2025 WIT.COM Inc. All rights reserved. +// Use of this source code is governed by the GPL 3.0 + +package main + +import ( + "fmt" + "strings" + + "go.wit.com/dev/alexflint/arg" + "go.wit.com/lib/debugger" + "go.wit.com/lib/fhelp" + "go.wit.com/lib/gui/logsettings" + "go.wit.com/lib/protobuf/argvpb" + "go.wit.com/log" +) + +// sent via -ldflags +var VERSION string +var BUILDTIME string + +// used for shell auto completion +var APPNAME string = "wit" // todo: get this from $0 ? + +func (args) MustParse() error { + me.pp = arg.MustParse(&argv) + return nil +} + +func init() { + if debugger.ArgDebug() { + log.Info("cmd line --debugger == true") + go func() { + log.Sleep(2) + debugger.DebugWindow() + }() + } + + if debugger.ArgLogger() { + log.Info("cmd line --loggger == true") + go func() { + log.Sleep(4) + logsettings.LogWindow() + logsettings.LogWindow() + }() + } +} + +func (args) ArgvGui() error { + me.myGui = fhelp.Gui() // adds the GUI package argv support + return nil +} + +func (a args) DoAutoComplete(pb *argvpb.Argv) { + base := []string{"build", "upgrade", "git", "publish", "pb", "linux", "droplet", "test"} + base = append(base, "--version", "--force", "--all", "--dry-run") + + // add these only if installed + if _, err := fhelp.CheckCmd("zood"); err == nil { + base = append(base, "zoo") + } + if _, err := fhelp.CheckCmd("forge"); err == nil { + base = append(base, "forge") + } + if _, err := fhelp.CheckCmd("go-clone"); err == nil { + base = append(base, "go-clone") + } + if areSuperuser() { + base = append(base, "upgrade") + base = append(base, "rdate") + } + if pb.GetCmd() == "" { + fmt.Fprintf(argvpb.Stdout, strings.Join(base, " ")) + return + } + var err error + if me.pp == nil { + me.pp, err = arg.ParseFlagsArgv(&argv) + fmt.Fprintf(argvpb.Stderr, "returned from parseFlagsArgv(%v)\n", err) + } + err = me.pp.WriteHelpForAutocomplete(argvpb.PB.Partial, argvpb.PB.Real...) + fmt.Fprintf(argvpb.Stderr, "returned from WriteHelpForAutocomplete() pb.Real(%v)\n", pb.Real) + fmt.Fprintf(argvpb.Stderr, "returned from WriteHelpForAutocomplete(%v)\n", err) +} diff --git a/doBuild.debian.go b/doBuild.debian.go index 9fb1dc7..637d3d6 100644 --- a/doBuild.debian.go +++ b/doBuild.debian.go @@ -16,6 +16,7 @@ import ( "go.wit.com/lib/env" "go.wit.com/lib/fhelp" "go.wit.com/lib/gui/shell" + "go.wit.com/lib/protobuf/argvpb" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" ) @@ -126,11 +127,11 @@ func doBuildDeb(all *gitpb.Repos) (string, error) { } if _, err := shell.RunVerbose([]string{"ls", "-l", "/home/jcarr/incoming"}); err != nil { - me.argv.BadExit("aptly failed", nil) + argvpb.BadExit("aptly failed", nil) } if _, err := fhelp.RunRealtimeError([]string{"do-aptly"}); err != nil { - me.argv.BadExit("aptly failed", nil) + argvpb.BadExit("aptly failed", nil) } return "all .deb built ok", nil } diff --git a/doBuild.go b/doBuild.go index fb78b6d..091f285 100644 --- a/doBuild.go +++ b/doBuild.go @@ -9,6 +9,7 @@ import ( "path/filepath" "strings" + "go.wit.com/lib/protobuf/argvpb" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" ) @@ -19,12 +20,12 @@ func doBuild() (string, error) { if argv.Build.Install != nil { if err := doInstall(me.forge.Repos); err != nil { // log.Info("doInstall() failed", err) - me.argv.BadExit("doInstall() failed", err) + argvpb.BadExit("doInstall() failed", err) } if argv.DryRun { - me.argv.GoodExit("Nothing built --dry-run") + argvpb.GoodExit("Nothing built --dry-run") } - me.argv.GoodExit("EVERYTHING BUILT!") + argvpb.GoodExit("EVERYTHING BUILT!") } if argv.Build.MacBuild != nil { @@ -58,7 +59,7 @@ func doBuild() (string, error) { /* if err := doInstall(found); err != nil { // log.Info("doInstall() failed", err) - me.argv.BadExit("doInstall() failed", err) + argvpb.BadExit("doInstall() failed", err) } return doBuildDeb(found) */ @@ -119,7 +120,7 @@ func doInstall(all *gitpb.Repos) error { failed.SortNamespace() footer = failed.PrintForgedTable() log.Info("TABLE WITH NULLS", footer) - me.argv.BadExit("go install Failed for: "+footer, nil) + argvpb.BadExit("go install Failed for: "+footer, nil) } return nil } diff --git a/doClone.go b/doClone.go index d2e5ffc..ccdcf08 100644 --- a/doClone.go +++ b/doClone.go @@ -9,6 +9,7 @@ import ( "go.wit.com/lib/config" "go.wit.com/lib/fhelp" + "go.wit.com/lib/protobuf/argvpb" "go.wit.com/log" ) @@ -82,7 +83,7 @@ func doClone() error { if _, err := fhelp.RunRealtimeError(cmd); err != nil { if !argv.Force { msg := fmt.Sprintf("failed: %v", cmd) - me.argv.BadExit(msg, err) + argvpb.BadExit(msg, err) } } } diff --git a/doGit.go b/doGit.go index f26a5cc..3ad057d 100644 --- a/doGit.go +++ b/doGit.go @@ -13,6 +13,7 @@ import ( "github.com/go-cmd/cmd" "go.wit.com/lib/fhelp" "go.wit.com/lib/gui/shell" + "go.wit.com/lib/protobuf/argvpb" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" ) @@ -95,7 +96,7 @@ func doGit() (string, error) { } else { log.Info("not installing") } - me.argv.GoodExit("git who should be installed") + argvpb.GoodExit("git who should be installed") } cmd := []string{"git", "who", "-l", "."} shell.RunVerbose(cmd) @@ -191,7 +192,7 @@ func doPush(wpath string) { if err := repo.GitCommit(); err != nil { msg := fmt.Sprintf("repo.GitCommit() %s", repo.FullPath) - me.argv.BadExit(msg, err) + argvpb.BadExit(msg, err) } repo.RunRealtime([]string{"git", "push"}) diff --git a/doPublish.go b/doPublish.go index a9e5be5..bd28a13 100644 --- a/doPublish.go +++ b/doPublish.go @@ -10,6 +10,7 @@ import ( "go.wit.com/lib/fhelp" "go.wit.com/lib/gui/shell" + "go.wit.com/lib/protobuf/argvpb" "go.wit.com/log" ) @@ -26,7 +27,7 @@ func doPublish() error { log.Info("$ENV[GUIRELEASE_REASON] was not set") reason := fhelp.InputFromUser("set tag message:") if reason == "" { - me.argv.BadExit("merge failed", fmt.Errorf("GUIRELEASE_REASON was blank")) + argvpb.BadExit("merge failed", fmt.Errorf("GUIRELEASE_REASON was blank")) } os.Setenv("GUIRELEASE_REASON", reason) } @@ -35,13 +36,13 @@ func doPublish() error { cmd = []string{"forge", "merge", "--all"} if _, err := shell.RunRealtimeError(cmd); err != nil { - me.argv.BadExit("merge failed", nil) + argvpb.BadExit("merge failed", nil) } cmd = []string{"forge", "merge", "check"} if _, err := shell.RunRealtimeError(cmd); err != nil { if _, err := shell.RunVerbose(cmd); err != nil { - me.argv.BadExit("merge failed", nil) + argvpb.BadExit("merge failed", nil) } } // todo: os.Stat() file @@ -50,7 +51,7 @@ func doPublish() error { if err := doInstall(me.forge.Repos); err != nil { log.Info("doInstall() failed", err) - me.argv.BadExit("merge failed", nil) + argvpb.BadExit("merge failed", nil) } if os.Getenv("GUIRELEASE_REASON") == "" { @@ -71,9 +72,9 @@ func doPublish() error { } if _, err := shell.RunRealtimeError(cmd); err != nil { log.Info("releaser failed", err) - me.argv.BadExit("publishing failed", nil) + argvpb.BadExit("publishing failed", nil) } - me.argv.GoodExit("PUBLISH WORKED") + argvpb.GoodExit("PUBLISH WORKED") return nil } diff --git a/doUpgrade.go b/doUpgrade.go index b04ce61..6dab951 100644 --- a/doUpgrade.go +++ b/doUpgrade.go @@ -7,6 +7,7 @@ import ( "fmt" "go.wit.com/lib/debian" + "go.wit.com/lib/protobuf/argvpb" "go.wit.com/lib/protobuf/zoopb" "go.wit.com/log" ) @@ -76,10 +77,10 @@ func doUpgrade() error { continue } if _, err := debian.AptInstall(p.Package); err != nil { - me.argv.BadExit("damn it", err) + argvpb.BadExit("damn it", err) } } } - me.argv.GoodExit("installed") + argvpb.GoodExit("installed") return nil } diff --git a/exit.go b/exit.go index 5dab98a..346df03 100644 --- a/exit.go +++ b/exit.go @@ -9,13 +9,14 @@ import ( "os" "go.wit.com/lib/gui/shell" + "go.wit.com/lib/protobuf/argvpb" "go.wit.com/log" ) // exits if not root func checkSuperuser() { if os.Getuid() != 0 { - me.argv.BadExit("need sudo", errors.New("this requires sudo acces")) + argvpb.BadExit("need sudo", errors.New("this requires sudo acces")) } } @@ -31,7 +32,7 @@ func exitOnError(cmd []string) { _, err = shell.RunVerbose(cmd) if err != nil { msg := fmt.Sprintf("Ran: %v", cmd) - me.argv.BadExit(msg, err) + argvpb.BadExit(msg, err) } } @@ -41,6 +42,6 @@ func exitOnErrorRealtime(cmd []string) { _, err = shell.RunRealtimeError(cmd) if err != nil { msg := fmt.Sprintf("Ran: %v", cmd) - me.argv.BadExit(msg, err) + argvpb.BadExit(msg, err) } } diff --git a/main.go b/main.go index e972da0..c25d5e5 100644 --- a/main.go +++ b/main.go @@ -17,18 +17,17 @@ var resources embed.FS func main() { me = new(mainType) - // autocomplete must be processed before there is anything sent to STDOUT or STDERR - me.argv = argvpb.Autocomplete(&argv) // adds shell auto complete to go-args - me.homedir, _ = os.UserHomeDir() // store shortcut here todo: add better logic + argvpb.Init(&argv, APPNAME, BUILDTIME, VERSION) // adds shell auto-complete + me.homedir, _ = os.UserHomeDir() // store shortcut here todo: add better logic - if me.argv.GetCmd() == "" { + if argvpb.GetCmd() == "" { // user didn't enter a sub command // doDefaultBehavior() - me.argv.GoodExit("do what?") + argvpb.GoodExit("do what?") } pwd, _ := os.Getwd() - setTitle(log.Sprintf("wit %s %s", me.argv.GetCmd(), pwd)) + setTitle(log.Sprintf("wit %s %s", argvpb.GetCmd(), pwd)) // Standard subcommand handling starts here var s string @@ -40,10 +39,10 @@ func main() { // argv provides timing and other features on exit if err != nil { // bad exit back to the shell via argv - me.argv.BadExit(s, err) + argvpb.BadExit(s, err) } // a good exit back to the shell via argv - me.argv.GoodExit(s) + argvpb.GoodExit(s) } // this is dumb. sync this with go-deb diff --git a/structs.go b/structs.go index be05974..93e0c4c 100644 --- a/structs.go +++ b/structs.go @@ -34,7 +34,7 @@ func initForge() { var err error me.forge, err = forgepb.Init() if err != nil { - me.argv.BadExit("this tool requires forge", err) + argvpb.BadExit("this tool requires forge", err) } me.forge.RescanRepos() } diff --git a/subCommand.go b/subCommand.go index fd75fc2..33078f0 100644 --- a/subCommand.go +++ b/subCommand.go @@ -4,6 +4,7 @@ package main import ( + "go.wit.com/lib/protobuf/argvpb" "go.wit.com/lib/protobuf/filepb" "go.wit.com/log" ) @@ -15,7 +16,7 @@ func subCommand() (string, error) { if argv.Upgrade != nil { doUpgrade() - me.argv.GoodExit("") + argvpb.GoodExit("") } if argv.Linux != nil { @@ -53,22 +54,22 @@ func subCommand() (string, error) { if argv.Clone != nil { doClone() - me.argv.GoodExit("") + argvpb.GoodExit("") } if argv.WITCOM { doWITCOM() - me.argv.GoodExit("") + argvpb.GoodExit("") } if argv.Clone != nil { doClone() - me.argv.GoodExit("") + argvpb.GoodExit("") } if argv.WITCOM { doWITCOM() - me.argv.GoodExit("") + argvpb.GoodExit("") } if argv.Upgrade != nil { @@ -81,16 +82,16 @@ func subCommand() (string, error) { if argv.Publish != nil { if err := doPublish(); err != nil { - me.argv.BadExit("doPublish failed", err) + argvpb.BadExit("doPublish failed", err) } - me.argv.GoodExit("") + argvpb.GoodExit("") } if argv.Zoo != nil { if areSuperuser() { exitOnErrorRealtime([]string{"journalctl", "-n", "100", "-f", "_SYSTEMD_UNIT=zood.service"}) } - me.argv.GoodExit("do something here") + argvpb.GoodExit("do something here") } return s, err } diff --git a/upgrade.go b/upgrade.go index f4c259d..fa629d1 100644 --- a/upgrade.go +++ b/upgrade.go @@ -6,6 +6,7 @@ package main import ( "fmt" + "go.wit.com/lib/protobuf/argvpb" "go.wit.com/log" ) @@ -41,5 +42,5 @@ func doAptList() { } log.Printf("%-30s %-8s %s\n", p.Package, p.Version, end) // p.PkgName) } - me.argv.GoodExit("") + argvpb.GoodExit("") } -- cgit v1.2.3