summaryrefslogtreecommitdiff
path: root/complete.go
diff options
context:
space:
mode:
Diffstat (limited to 'complete.go')
-rw-r--r--complete.go95
1 files changed, 17 insertions, 78 deletions
diff --git a/complete.go b/complete.go
index 3f4ff60..e82510b 100644
--- a/complete.go
+++ b/complete.go
@@ -81,6 +81,19 @@ func (pb *Auto) doHandlePB() error {
func (pb *Auto) SubCommand(cmd ...string) {
partial := strings.Trim(pb.Partial, "'")
if pb.Debug {
+ if myAuto.examples == nil {
+ log.Fprintf(os.Stderr, "\n")
+ log.Fprintf(os.Stderr, "examples was nil\n")
+ // log.Fprintf(os.Stderr, "\n")
+ } else {
+ log.Fprintf(os.Stderr, "\n")
+ log.Fprintf(os.Stderr, "\n")
+ log.Fprintf(os.Stderr, "Examples:\n")
+ for _, line := range strings.Split(myAuto.examples(), "\n") {
+ log.Fprintf(os.Stderr, " %s\n", line)
+ }
+ // log.Fprintf(os.Stderr, "\n")
+ }
myAuto.pp.WriteHelpForAutocomplete(os.Stderr, os.Stdout, partial, cmd...)
// myAuto.pp.GetUsageForSubcommand(os.Stdout, os.Stderr, partial, cmd)
// myAuto.pp.GetUsageForSubcommand(os.Stdout, nil, partial, cmd)
@@ -249,9 +262,11 @@ func parseArgv(argname string) *Auto {
return pb
}
-// also try to parse/send cur (?)
-// func Bash3(appAutoFunc func(*Auto), dest any) *Auto {
func Bash3(dest any) *Auto {
+ return Bash(dest)
+}
+
+func Bash(dest any) *Auto {
myAuto = new(AutoArgs)
findAppInfo(dest) // parses back to main() for argv info
@@ -355,79 +370,3 @@ func doBash(argname string) {
}
os.Exit(0)
}
-
-/*
-// also try to parse/send cur (?)
-func Bash2(argname string, appAutoFunc func(*Auto)) *Auto {
- pb := parseArgv(argname)
- if pb.SetupAuto {
- // --bash was passed. try to configure bash-completion
- doBash2(argname)
- os.Exit(0)
- }
-
- if pb.Debug {
- // dump debug info
- pb.PrintDebug()
- }
-
- if pb.IsAuto {
- pb.doHandlePB()
- if pb.Debug {
- // TODO:
- // check here to see if there was any completion text sent
- // if not, send "reset bash newline\n" to cause bash to redraw PS1 for the user
- }
- arg.Register(&argBash)
- // flags := []string{pb.Arg3, pb.Arg0}
- // arg.InitFlags(flags)
-
- appAutoFunc(pb) // run the autocomplete function the user made for their application
- os.Exit(0)
- }
-
- arg.Register(&argBash)
- return pb
-}
-*/
-
-/*
-// prints help to STDERR // TODO: move everything below this to go-args
-func (args) doBashHelp() {
- if argv.BashAuto[1] != "''" {
- // if this is not blank, then the user has typed something
- return
- }
- if argv.BashAuto[0] != ARGNAME {
- // if this is not the name of the command, the user already started doing something
- return
- }
- if argv.BashAuto[0] == ARGNAME {
- me.pp.WriteHelp(os.Stderr)
- return
- }
- fmt.Fprintln(os.Stderr, "")
- fmt.Fprintln(os.Stderr, "hello world")
- fmt.Fprintln(os.Stderr, "")
-}
-*/
-
-/*
-func (pb *Auto) Autocomplete(notsure any, sendthis string) {
- parts := strings.Split(sendthis, " ")
- var all []string
- for _, part := range parts {
- var found bool
- for _, s := range os.Args {
- if s == part {
- found = true
- }
- }
- if found {
- continue
- }
- all = append(all, part)
- }
- fmt.Printf("%s", strings.Join(all, " "))
-}
-*/