summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bash.go10
-rw-r--r--structs.go2
-rw-r--r--theMagicOfAutocomplete.go39
3 files changed, 25 insertions, 26 deletions
diff --git a/bash.go b/bash.go
index 2602513..0cef75c 100644
--- a/bash.go
+++ b/bash.go
@@ -9,6 +9,16 @@ import (
"strings"
)
+// deprecate this
+func Bash3(dest any) *Auto {
+ return Autocomplete(dest)
+}
+
+// deprecate this
+func Bash(dest any) *Auto {
+ return Autocomplete(dest)
+}
+
func makeCompletionText(argname string) string {
sh := getParentProcessName()
return fmt.Sprintf("# shell might be %s", sh)
diff --git a/structs.go b/structs.go
index 5b28289..4dadcd2 100644
--- a/structs.go
+++ b/structs.go
@@ -35,7 +35,7 @@ type AutoArgs struct {
buildtime func() (string, string) // some examples
pp *arg.Parser // for parsing the command line args. Yay to alexf lint!
autoFunc func(*Auto) // also a function for autocomplete
- match map[string]string // maps for strings
+ // match map[string]string // maps for strings
}
// print out auto complete debugging info
diff --git a/theMagicOfAutocomplete.go b/theMagicOfAutocomplete.go
index 9397373..9de2d7f 100644
--- a/theMagicOfAutocomplete.go
+++ b/theMagicOfAutocomplete.go
@@ -14,30 +14,17 @@ import (
"go.wit.com/log"
)
-// deprecate
-func Bash3(dest any) *Auto {
- return Autocomplete(dest)
-}
-
-// deprecate
-func Bash(dest any) *Auto {
- return Autocomplete(dest)
-}
-
func Autocomplete(dest any) *Auto {
myAuto = new(AutoArgs)
findAppInfo(dest) // parses back to main() for argv info
- pb := parseArgv(myAuto.appName)
+ pb := parseArgv(myAuto.appName) // parses os.Args into a protobuf
if pb.SetupAuto {
// --bash was passed. try to configure bash-completion
- doBash(myAuto.appName)
+ makeAutocompleteFiles(myAuto.appName)
os.Exit(0)
}
- myAuto.match = make(map[string]string)
- myAuto.match["--gui"] = "andlabs gocui"
-
if pb.Debug {
// dump debug info
pb.PrintDebug()
@@ -76,15 +63,17 @@ func Autocomplete(dest any) *Auto {
}
if pb.IsAuto {
- for key, val := range myAuto.match {
- if pb.Last == key {
- pb.Debugf("DEBUG: last=%s found key %s = %s", pb.Last, key, val)
- pb.Autocomplete2(val)
- os.Exit(0)
- } else {
- // pb.Debugf("DEBUG: NO MATCH last='%s' found key '%s' = %s", pb.Last, key, val)
- }
+ // myAuto.match = make(map[string]string)
+ // myAuto.match["--gui"] = "andlabs gocui"
+ // for key, val := range myAuto.match {
+ if pb.Last == "--gui" {
+ pb.Debugf("DEBUG: last=%s found --gui", pb.Last)
+ pb.Autocomplete2("andlabs gogui")
+ os.Exit(0)
+ } else {
+ // pb.Debugf("DEBUG: NO MATCH last='%s' found key '%s' = %s", pb.Last, key, val)
}
+ // }
if myAuto.autoFunc == nil {
pb.SubCommand(pb.Argv...)
} else {
@@ -103,8 +92,8 @@ func Autocomplete(dest any) *Auto {
return pb
}
-// makes a bash autocomplete file for your command
-func doBash(argname string) {
+// makes a autocomplete file for your command
+func makeAutocompleteFiles(argname string) {
fmt.Println(makeBashCompletionText2(argname))
homeDir, err := os.UserHomeDir()