summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-10-25 14:51:30 -0500
committerJeff Carr <[email protected]>2025-10-25 14:51:30 -0500
commit418f790437ac264ede889604f31e6d81c7d35cd0 (patch)
treed073e7933824c4ae815bda411bf1ee7441f4dd47
parent22fcb080548bc57847c2405d724e9f40364fa621 (diff)
compiles and does something. notsure
-rw-r--r--argv.Print.go9
-rw-r--r--argv.SendStrings.go5
-rw-r--r--argv.parseOsArgs.go7
-rw-r--r--structs.go10
-rw-r--r--theMagicOfAutocomplete.go99
-rw-r--r--verifyApplication.go26
6 files changed, 94 insertions, 62 deletions
diff --git a/argv.Print.go b/argv.Print.go
index 53b080a..ed6f75e 100644
--- a/argv.Print.go
+++ b/argv.Print.go
@@ -40,8 +40,15 @@ func (pb *Argv) PrintDebugNew(msg string, last string) {
} else {
fast = "fast=0," + pb.GetCmd()
}
+
+ var dbg string
+ if me.debug {
+ dbg = "dbg=1"
+ } else {
+ dbg = "dbg=0"
+ }
sargv := fmt.Sprintf("argv(%v)", pb.Real)
- top := fmt.Sprintf("%-4.4s age=(%s)dur(%s) h%2.2d %-12.12s %-12.12s", pb.Uuid, age, dur, pb.HelpCounter, cmd, arglast)
+ top := fmt.Sprintf("%-4.4s age=(%s)dur(%s) %s h%2d %-12.12s %-12.12s", pb.Uuid, age, dur, dbg, pb.HelpCounter, cmd, arglast)
Debugf("%s: %s %-12.12s %s %s real='%v' len(%d)", msg, top, partial, fast, sargv, pb.Real, me.all.Len())
}
diff --git a/argv.SendStrings.go b/argv.SendStrings.go
index 4e074e0..4467d06 100644
--- a/argv.SendStrings.go
+++ b/argv.SendStrings.go
@@ -48,16 +48,15 @@ func (pb *Argv) SubCommand(cmd ...string) {
pb.Stderr += fmt.Sprintf(" %s\n", line)
}
}
- partial := strings.Trim(pb.Partial, "'")
if me.debug {
// last working line: me.writeHelpForAutocomplete(Stderr, Stdout, partial, cmd...)
- me.writeHelpForAutocompleteDebugFunc(partial, cmd...)
+ me.writeHelpForAutocompleteDebugFunc()
// me.pp.GetUsageForSubcommand(Stdout, Stderr, partial, cmd)
// me.pp.GetUsageForSubcommand(Stdout, nil, partial, cmd)
} else {
// last working: me.writeHelpForAutocomplete(f, Stdout, partial, cmd...)
- me.writeHelpForAutocompleteFunc(partial, cmd...)
+ me.writeHelpForAutocompleteFunc()
}
os.Exit(0)
}
diff --git a/argv.parseOsArgs.go b/argv.parseOsArgs.go
index d28e7e7..b7d4774 100644
--- a/argv.parseOsArgs.go
+++ b/argv.parseOsArgs.go
@@ -8,10 +8,15 @@ import (
"strings"
)
+func GetCmd() string {
+ return PB.GetCmd()
+}
+
// todo: this is wrong
func (pb *Argv) GetCmd() string {
var curcmd string
- for _, s := range os.Args[1:] {
+ // for _, s := range os.Args[1:] {
+ for _, s := range pb.Real {
if strings.HasPrefix(s, "-") {
// option is something like --verbose
// skip these. they are not subcommands
diff --git a/structs.go b/structs.go
index 3a0544e..57635de 100644
--- a/structs.go
+++ b/structs.go
@@ -3,6 +3,8 @@ package argvpb
// try this struct out (?)
var me *AutoArgs
+var PB *Argv
+
// this is a work in progress
type AutoArgs struct {
pb *Argv // the protobuf for the current process
@@ -17,11 +19,11 @@ type AutoArgs struct {
initArgvFunc func() (string, string, string) // this is required. gets APPNAME, BUILDTIME & VERSION
initGuiFunc func() error // this is required for 'gui' args to work
mustParseFunc func() error // calls go-arg.MustParse()
- parseFlagsFunc func([]string) error // calls go-arg.ParseFlags(flags)
- writeHelpForAutocompleteFunc func(string, ...string) error // notsure yet
- writeHelpForAutocompleteDebugFunc func(string, ...string) error // notsure yet
+ parseFlagsFunc func() error // calls go-arg.ParseFlags(flags)
+ writeHelpForAutocompleteFunc func() error // notsure yet
+ writeHelpForAutocompleteDebugFunc func() error // notsure yet
writeHelpFunc func() error // notsure yet
- writeHelpForSubcommandFunc func(string) error // notsure yet
+ writeHelpForSubcommandFunc func() error // notsure yet
examples func() string // some examples
appExit func() // app Exit()
buildtime func() (string, string) // some examples
diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go
index 85b89b0..13cf020 100644
--- a/theMagicOfAutocomplete.go
+++ b/theMagicOfAutocomplete.go
@@ -25,6 +25,7 @@ import (
func Autocomplete(dest any) *Argv {
me = new(AutoArgs) // todo: redo this
me.pb = new(Argv)
+ PB = me.pb
me.pb.Uuid = uuid.New().String()
// set the start time of the binary
@@ -74,18 +75,19 @@ func Autocomplete(dest any) *Argv {
}
}
- if me.isAuto {
- // do autocomplete and exit
+ if !me.isAuto {
+ // not autocompleting. return to the application
+ // save the pb & history
savePB()
- doAutocomplete()
- panic("blah")
+ // me.pp = arg.MustParse(dest)
+ me.Err = errors.Join(me.Err, me.mustParseFunc())
+ return me.pb
}
- // not autocompleting. return to the application
- // save the pb & history
- savePB()
- // me.pp = arg.MustParse(dest)
- me.Err = errors.Join(me.Err, me.mustParseFunc())
+ prepareStdout()
+ // print to Stdout & Stderr
+ saveAndExit()
+ // never gets here
return me.pb
}
@@ -93,17 +95,7 @@ func Autocomplete(dest any) *Argv {
//
// everything sent to STDOUT and STDERR matters past this point
// any "junk" output, hidden fmt(), print() or log() statements are bad
-func doAutocomplete() {
- if me.last.Fast {
- // user is probably holding down the <TAB> key
- me.debug = true
- // me.fastcmd = me.pb.GetCmd()
- if me.pb.GetCmd() != me.last.GetCmd() {
- // do the smart something here
- // probably debug == true && printStderr()
- }
- }
-
+func prepareStdout() {
if me.debug {
// add an initial debug line
me.pb.PrintDebug(me.last.GetCmd())
@@ -113,8 +105,7 @@ func doAutocomplete() {
me.pb.SendString("--argvdebug --argvhelp")
me.pb.Stderr += fmt.Sprintln("argv override")
me.debug = true
- me.pb.PrintStderr()
- saveAndExit()
+ return
}
// highjack "--gui"
@@ -123,9 +114,8 @@ func doAutocomplete() {
// this is a work in progress
if lastarg == "--gui" {
me.pb.Debugf("DEBUG: real=(%v) found --gui", me.pb.Real)
- me.pb.PrintStderr()
me.pb.SendString("andlabs gogui")
- saveAndExit()
+ return
} else {
// me.pb.Debugf("DEBUG: NO MATCH last='%s' found key '%s' = %s", last, key, val)
}
@@ -136,19 +126,15 @@ func doAutocomplete() {
if me.parseFlagsFunc == nil {
me.pb.Stderr += fmt.Sprintln("argv.parseFlags() is nil")
me.debug = true
- me.pb.PrintStderr()
- me.pb.PrintStdout()
- saveAndExit()
+ return
}
- if err := me.parseFlagsFunc(me.pb.Real); err != nil {
+ if err := me.parseFlagsFunc(); err != nil {
me.pb.Stderr += fmt.Sprintf("application parseFlags() err(%v)\n", err)
me.pb.Stderr += fmt.Sprintln("argv.parseFlags() err. probably cmd doesn't really exist in struct")
me.all.PrintHistory(me.last.GetCmd())
me.debug = true
- me.pb.PrintStderr()
- me.pb.PrintStdout()
- saveAndExit()
+ return
}
if len(me.pb.Real) == 0 {
@@ -161,15 +147,20 @@ func doAutocomplete() {
}
me.pb.HelpCounter = me.last.HelpCounter
+ /*
+ if me.last.Fast {
+ // user is probably holding down the <TAB> key
+ // me.fastcmd = me.pb.GetCmd()
+ if me.pb.GetCmd() != me.last.GetCmd() {
+ // do the smart something here
+ // probably debug == true && printStderr()
+ }
+ }
+ */
+
if me.pb.Fast {
if me.last.Fast {
- me.debug = true
me.pb.HelpCounter = me.last.HelpCounter + 1
- if me.pb.HelpCounter < 3 {
- me.pb.PrintStderr()
- } else {
- saveAndExit()
- }
} else {
// this means the user is pressing tab. no longer doing stderr
if me.pb.GetCmd() == "" {
@@ -177,7 +168,7 @@ func doAutocomplete() {
me.writeHelpFunc()
} else {
// me.pp.WriteHelpForSubcommand(Stderr, me.pb.Cmd)
- me.writeHelpForSubcommandFunc(me.pb.GetCmd())
+ me.writeHelpForSubcommandFunc()
}
me.pb.HelpCounter = 0
}
@@ -193,7 +184,7 @@ func doAutocomplete() {
// if not, send "reset bash newline\n" to cause bash to redraw PS1 for the user
}
}
- saveAndExit()
+ return
}
func savePB() {
@@ -206,6 +197,17 @@ func savePB() {
}
func saveAndExit() {
+ if me.debug {
+ me.all.PrintHistory(me.last.GetCmd())
+ me.pb.PrintStderr()
+ } else {
+ if me.pb.Fast {
+ if me.pb.HelpCounter < 3 {
+ me.pb.PrintStderr()
+ }
+ }
+ }
+ me.pb.PrintStdout()
savePB()
os.Exit(0)
}
@@ -230,7 +232,9 @@ func examineArgvHistory() {
panic("argvpb.Load() history file failed")
}
if me.debug {
+ // use this if you are having trouble debugging this code
// me.all.PrintHistory("EARLY")
+ // me.pb.PrintStderr()
}
// roll the autocomplete file
maxsize := 17
@@ -244,14 +248,28 @@ func examineArgvHistory() {
}
// drops nil entries from the history
+ // even gets dup uuids. don't have time to figure this out now
+ // need to launch the WIT private cloud product
// todo: figure out why nil values are happening
+ // a facinating PITA this is
counter := 0
+ uuidmap := make(map[string]*Argv)
for pb := range me.all.IterAll() {
counter += 1
if pb.Ctime == nil {
me.all.Delete(pb)
continue
}
+ if pb.Uuid == "" {
+ me.all.Delete(pb)
+ continue
+ }
+ if _, ok := uuidmap[pb.Uuid]; ok {
+ // already have this uuid, keep the oldest one
+ me.all.Delete(pb)
+ continue
+ }
+ uuidmap[pb.Uuid] = pb
// if me.debug {
// hist := fmt.Sprintf("HISTNIL(%d)", counter)
// pb.PrintDebugNew(hist, "too soon")
@@ -282,8 +300,9 @@ func examineArgvHistory() {
// do the smart something here
if me.pb.GetCmd() == me.last.GetCmd() {
// turn on debugging if duration < 200 milliseconds
- // me.debug = false
} else {
+ // reset help counter
+ me.pb.HelpCounter = 0
}
}
}
diff --git a/verifyApplication.go b/verifyApplication.go
index 7c79cd9..6b0291a 100644
--- a/verifyApplication.go
+++ b/verifyApplication.go
@@ -92,19 +92,19 @@ type mustParseI interface {
}
type parseFlagsI interface {
- ParseFlags([]string) error
+ ParseFlags() error
}
type writeHelpForAutocompleteI interface {
- WriteHelpForAutocomplete(string, ...string) error
+ WriteHelpForAutocomplete() error
}
type writeHelpForAutocompleteDebugI interface {
- WriteHelpForAutocompleteDebug(string, ...string) error
+ WriteHelpForAutocompleteDebug() error
}
type writeHelpForSubcommandI interface {
- WriteHelpForSubcommand(cmd string) error
+ WriteHelpForSubcommand() error
}
type writeHelpI interface {
@@ -163,8 +163,8 @@ type exitI interface {
func helpWriteHelpForSubcommand() {
fmt.Println("")
fmt.Println("// add this funcgion: this will print the help")
- fmt.Println("func (args) WriteHelpForSubcommand() error {")
- fmt.Println(" me.pp.WriteHelpForSubcommand(Stderr, me.argv.Cmd)")
+ fmt.Println("func (args) WriteHelpForSubcommandArgv() error {")
+ fmt.Println(" me.pp.WriteHelpForSubcommandArgv(me.argv)")
fmt.Println(" return nil")
fmt.Println("}")
fmt.Println("")
@@ -176,7 +176,7 @@ func helpWriteHelp() {
fmt.Println("")
fmt.Println("// add this funcgion: this will print the help")
fmt.Println("func (args) WriteHelp() error {")
- fmt.Println(" me.pp.WriteHelp(Stderr)")
+ fmt.Println(" me.pp.WriteHelpArgv(me.argv)")
fmt.Println(" return nil")
fmt.Println("}")
fmt.Println("")
@@ -187,8 +187,8 @@ func helpWriteHelp() {
func helpWriteHelpForAutocompleteDebug() {
fmt.Println("")
fmt.Println("// this will print the help for the subcmd")
- fmt.Println("func (args) WriteHelpForAutocompleteDebug(part string, subcmd ...string) error {")
- fmt.Println(" return argvpp.WriteHelpForAutocomplete(f, Stdout, part, subcmd...)")
+ fmt.Println("func (args) WriteHelpForAutocompleteDebugArgv() error {")
+ fmt.Println(" return argvpp.WriteHelpForAutocompleteArgv(me.argv)")
fmt.Println("}")
fmt.Println("")
fmt.Println("cp ~/go/src/go.wit.com/apps/forge/argv.template.go .")
@@ -201,8 +201,8 @@ func helpWriteHelpForAutocompleteDebug() {
func helpWriteHelpForAutocomplete() {
fmt.Println("")
fmt.Println("// this will print the help for the subcmd")
- fmt.Println("func (args) WriteHelpForAutocomplete(part string, subcmd ...string) error {")
- fmt.Println(" return argvpp.WriteHelpForAutocomplete(Stderr, Stdout, part, subcmd...)")
+ fmt.Println("func (args) WriteHelpForAutocompleteArgv() error {")
+ fmt.Println(" return argvpp.WriteHelpForAutocompleteArgv(me.argv)")
fmt.Println("}")
fmt.Println("")
fmt.Println("Just copy the argv.template.go file from forge")
@@ -214,8 +214,8 @@ func helpWriteHelpForAutocomplete() {
func parseFlagsHelp() {
fmt.Println("")
fmt.Println("// this function will send the current argv PB to go-args for parsing")
- fmt.Println("func (args) ParseFlags(flags []string) error {")
- fmt.Println(" arg.ParseFlags(flags)")
+ fmt.Println("func (args) ParseFlags() error {")
+ fmt.Println(" arg.ParseFlags(me.argv, &argv)")
fmt.Println("}")
fmt.Println("")