summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--argv.Print.go17
-rw-r--r--argv.proto11
-rw-r--r--structs.go2
-rw-r--r--theMagicOfAutocomplete.go29
4 files changed, 24 insertions, 35 deletions
diff --git a/argv.Print.go b/argv.Print.go
index 2fcd859..53b080a 100644
--- a/argv.Print.go
+++ b/argv.Print.go
@@ -42,7 +42,7 @@ func (pb *Argv) PrintDebugNew(msg string, last string) {
}
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)
- Debugf("%s: %s %-12.12s %s %s goargs='%v' len(%d)", msg, top, partial, fast, sargv, pb.Goargs, me.all.Len())
+ Debugf("%s: %s %-12.12s %s %s real='%v' len(%d)", msg, top, partial, fast, sargv, pb.Real, me.all.Len())
}
func (all *Argvs) PrintHistory(last string) {
@@ -57,11 +57,11 @@ func (all *Argvs) PrintHistory(last string) {
func (pb *Argv) PrintStderr() {
if !me.debug {
- os.Exit(0)
+ return
}
lines := strings.Split(strings.TrimSpace(pb.Stderr), "\n")
if len(lines) == 0 {
- os.Exit(0)
+ return
}
fmt.Fprintf(os.Stderr, "\n")
for _, line := range lines {
@@ -76,14 +76,3 @@ func (pb *Argv) PrintStderr() {
func (pb *Argv) PrintStdout() {
fmt.Fprintf(os.Stdout, "%s\n", pb.Stdout)
}
-
-func (pb *Argv) PrintStderrExit() {
- pb.PrintStderr()
- pb.PrintStdout()
- os.Exit(0)
-}
-
-func (pb *Argv) PrintStdoutExit() {
- pb.PrintStdout()
- os.Exit(0)
-}
diff --git a/argv.proto b/argv.proto
index 3cf85b9..c203386 100644
--- a/argv.proto
+++ b/argv.proto
@@ -34,12 +34,11 @@ message Argv { // `autogenpb:marshal
repeated string real = 5; // what will really be sent to the application
string subcmd = 6; // the subcommand being processed. For "git pull <tab>", cmd would be "pull"
string partial = 7; // if the user has only partially inputed something
- repeated string goargs = 8; // what to send to alex flint's go-args for help
- bool fast = 9; // is autocomplete running quickly?
- string stdout = 10; // all output is loaded here before being sent to the shell
- string stderr = 11; // all output is loaded here before being sent to the shell
- int32 helpCounter = 12; // counter to track if the help text has been sent to Stderr
- string uuid = 13; // all output is loaded here before being sent to the shell
+ bool fast = 8; // is autocomplete running quickly?
+ string stdout = 9; // all output is loaded here before being sent to the shell
+ string stderr = 10; // all output is loaded here before being sent to the shell
+ int32 helpCounter = 11; // counter to track if the help text has been sent to Stderr
+ string uuid = 12; // all output is loaded here before being sent to the shell
}
message Argvs { // `autogenpb:marshal` `autogenpb:sort` `autogenpb:nomutex`
diff --git a/structs.go b/structs.go
index 1c42be8..3a0544e 100644
--- a/structs.go
+++ b/structs.go
@@ -8,7 +8,6 @@ type AutoArgs struct {
pb *Argv // the protobuf for the current process
all *Argvs // the history of argv
last *Argv // the pb from the last time the user tried autocomplete
- flags []string // notsure
Err error // store any errors from argv
debug bool // is dubugging on?
setupAuto bool // do shell autocomplete setup
@@ -28,4 +27,5 @@ type AutoArgs struct {
buildtime func() (string, string) // some examples
autoFunc func(*Argv) // also a function for autocomplete
guiFunc func() error // enables Gui functions
+ // flags []string // notsure
}
diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go
index a2ff7a9..85b89b0 100644
--- a/theMagicOfAutocomplete.go
+++ b/theMagicOfAutocomplete.go
@@ -64,7 +64,6 @@ func Autocomplete(dest any) *Argv {
// --bash or --zsh was passed. try to configure bash-completion
MakeAutocompleteFiles(me.pb.AppInfo.APPNAME)
// never forget to exit here or you will hate yourself and the choices you have made
- savePB()
saveAndExit()
}
@@ -106,17 +105,16 @@ func doAutocomplete() {
}
if me.debug {
- // dump debug info
+ // add an initial debug line
me.pb.PrintDebug(me.last.GetCmd())
- // me.all.PrintHistory()
- // me.pb.PrintStderr()
}
if strings.HasPrefix(me.pb.Partial, "--argv") {
me.pb.SendString("--argvdebug --argvhelp")
me.pb.Stderr += fmt.Sprintln("argv override")
me.debug = true
- me.pb.PrintStderrExit()
+ me.pb.PrintStderr()
+ saveAndExit()
}
// highjack "--gui"
@@ -127,7 +125,6 @@ func doAutocomplete() {
me.pb.Debugf("DEBUG: real=(%v) found --gui", me.pb.Real)
me.pb.PrintStderr()
me.pb.SendString("andlabs gogui")
- savePB()
saveAndExit()
} else {
// me.pb.Debugf("DEBUG: NO MATCH last='%s' found key '%s' = %s", last, key, val)
@@ -135,26 +132,31 @@ func doAutocomplete() {
}
// use go-args to parse the structs so we can use them here
- // me.pp, err = arg.ParseFlags(flags, dest)
+ // me.pp, err = arg.ParseFlags(pb.Real, dest)
if me.parseFlagsFunc == nil {
me.pb.Stderr += fmt.Sprintln("argv.parseFlags() is nil")
me.debug = true
- me.pb.PrintStderrExit()
+ me.pb.PrintStderr()
+ me.pb.PrintStdout()
+ saveAndExit()
}
- if err := me.parseFlagsFunc(me.flags); err != nil {
+ if err := me.parseFlagsFunc(me.pb.Real); 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.PrintStderrExit()
+ me.pb.PrintStderr()
+ me.pb.PrintStdout()
+ saveAndExit()
}
- if len(me.flags) == 0 {
+ if len(me.pb.Real) == 0 {
// error is normal if there are no command line args
} else {
if me.Err != nil {
// users has command line arguments that won't parse with go-args
- me.pb.Debugf("DEBUG: Parse error: %v flags%v", me.Err, me.flags)
+ me.pb.Debugf("DEBUG: Parse error: %v real(%v)", me.Err, me.pb.Real)
}
}
@@ -166,7 +168,6 @@ func doAutocomplete() {
if me.pb.HelpCounter < 3 {
me.pb.PrintStderr()
} else {
- savePB()
saveAndExit()
}
} else {
@@ -192,7 +193,6 @@ func doAutocomplete() {
// if not, send "reset bash newline\n" to cause bash to redraw PS1 for the user
}
}
- savePB()
saveAndExit()
}
@@ -206,6 +206,7 @@ func savePB() {
}
func saveAndExit() {
+ savePB()
os.Exit(0)
}