summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-18 11:53:14 -0500
committerJeff Carr <[email protected]>2025-10-18 11:53:14 -0500
commit3a7d5a176350447cf568d9fbc7ea804895549968 (patch)
tree9df0aebff512050f84634ff02967ad00107fd2ed
parent94fd646c63f0d85083c991ea219d34197aaa085e (diff)
the long road to betterness
-rw-r--r--argv.custom.go92
-rw-r--r--argv.struct.go (renamed from argv.go)76
-rw-r--r--argv.template.go74
-rw-r--r--main.go7
-rw-r--r--resources/TESTVERSION22
-rw-r--r--structs.go2
6 files changed, 190 insertions, 83 deletions
diff --git a/argv.custom.go b/argv.custom.go
new file mode 100644
index 0000000..c8c97be
--- /dev/null
+++ b/argv.custom.go
@@ -0,0 +1,92 @@
+// 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"}
+ base = append(base, "--version", "--force", "--all")
+
+ // 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.Cmd == "" {
+ pb.SendStrings(base)
+ } else {
+ pb.SubCommand(pb.Goargs...)
+ }
+ os.Exit(0)
+}
diff --git a/argv.go b/argv.struct.go
index 81d8431..2414ac2 100644
--- a/argv.go
+++ b/argv.struct.go
@@ -8,16 +8,6 @@ package main
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"
-)
-
var argv args
type args struct {
@@ -116,69 +106,3 @@ type GitCmd struct {
type EmptyCmd struct {
}
-
-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 ARGNAME
-}
-
-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"}
- base = append(base, "--version", "--force", "--all")
-
- // 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.Cmd == "" {
- pb.SendStrings(base)
- } else {
- pb.SubCommand(pb.Goargs...)
- }
- os.Exit(0)
-}
diff --git a/argv.template.go b/argv.template.go
new file mode 100644
index 0000000..d438b20
--- /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/main.go b/main.go
index 5672d44..1731828 100644
--- a/main.go
+++ b/main.go
@@ -13,13 +13,6 @@ import (
"go.wit.com/log"
)
-// sent via -ldflags
-var VERSION string
-var BUILDTIME string
-
-// used for shell auto completion
-var ARGNAME string = "wit" // todo: get this from $0 ?
-
//go:embed resources/*
var resources embed.FS
diff --git a/resources/TESTVERSION b/resources/TESTVERSION
new file mode 100644
index 0000000..92bb4ed
--- /dev/null
+++ b/resources/TESTVERSION
@@ -0,0 +1,22 @@
+-rwxr-xr-x 1 jcarr jcarr 19014488 Oct 18 11:15 basicwindow
+-rwxr-xr-x 1 jcarr jcarr 24416080 Oct 18 11:13 forge
+-rwxr-xr-x 1 jcarr jcarr 24309824 Oct 18 11:11 wit
+-rwxr-xr-x 1 jcarr jcarr 37211480 Oct 18 10:43 gus
+-rwxr-xr-x 1 jcarr jcarr 21406968 Oct 18 10:43 zood
+-rwxr-xr-x 1 jcarr jcarr 25231576 Oct 18 10:43 virtigod
+-rwxr-xr-x 1 jcarr jcarr 23480008 Oct 18 10:43 gowebd
+-rwxr-xr-x 1 jcarr jcarr 24697680 Oct 18 10:43 guireleaser
+-rwxr-xr-x 1 jcarr jcarr 22481568 Oct 18 10:43 go-gui-toolkits
+-rwxr-xr-x 1 jcarr jcarr 22606424 Oct 18 10:43 go-mod-clean
+-rwxr-xr-x 1 jcarr jcarr 22574936 Oct 18 10:43 go-clone
+-rwxr-xr-x 1 jcarr jcarr 23427472 Oct 18 10:43 virtigo
+-rwxr-xr-x 1 jcarr jcarr 32913280 Oct 18 10:43 regex
+-rwxr-xr-x 1 jcarr jcarr 21725120 Oct 18 10:43 zookeeper
+-rwxr-xr-x 1 jcarr jcarr 22644600 Oct 18 10:43 go-deb
+-rwxr-xr-x 1 jcarr jcarr 20928632 Oct 18 10:43 virtigoctl
+-rwxr-xr-x 1 jcarr jcarr 21523896 Oct 18 10:43 jcarrgitpull
+-rwxr-xr-x 1 jcarr jcarr 22328608 Oct 18 10:43 fixup
+-rwxr-xr-x 1 jcarr jcarr 21460328 Oct 18 10:43 mirrors
+-rwxr-xr-x 1 jcarr jcarr 9937936 Oct 18 10:43 going2git
+-rwxr-xr-x 1 jcarr jcarr 9444608 Oct 18 10:43 startxplacement
+-rwxr-xr-x 1 jcarr jcarr 8701912 Oct 18 10:43 powerpaneld
diff --git a/structs.go b/structs.go
index 4ab8dd7..732bb2a 100644
--- a/structs.go
+++ b/structs.go
@@ -6,6 +6,7 @@ package main
import (
"sync"
+ "go.wit.com/dev/alexflint/arg"
"go.wit.com/lib/debian"
"go.wit.com/lib/fhelp"
"go.wit.com/lib/protobuf/argvpb"
@@ -19,6 +20,7 @@ var me *mainType
type mainType struct {
once sync.Once // one-time initialized data
argv *argvpb.Argv // more experiments for bash handling
+ pp *arg.Parser // for parsing the command line args. Yay to alexf lint!
forge *forgepb.Forge // your customized repo preferences and settings
machine *zoopb.Machine // your customized repo preferences and settings
homedir string // where the user homedir is