diff options
| author | Jeff Carr <[email protected]> | 2025-09-25 00:44:44 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-09-25 00:44:44 -0500 |
| commit | 3297ac713e589db0223fe734e0400d8e8459bdf5 (patch) | |
| tree | 95fffb007e07abe2ad8870fd521499f544a2c015 | |
| parent | 9f4fc6ecddd88c9d2d84bc1960f1b78ea56cc85c (diff) | |
more accurate autocompletev1.6.4
| -rw-r--r-- | complete.go | 66 |
1 files changed, 37 insertions, 29 deletions
diff --git a/complete.go b/complete.go index 72f964d..1c815ec 100644 --- a/complete.go +++ b/complete.go @@ -28,7 +28,7 @@ func (p *Parser) WriteHelpForAutocomplete(stderr io.Writer, stdout io.Writer, pa } var positionals, longOptions, shortOptions, envOnlyOptions []*spec - var hasVersionOption bool + // var hasVersionOption bool for _, spec := range cmd.specs { switch { case spec.positional: @@ -36,7 +36,7 @@ func (p *Parser) WriteHelpForAutocomplete(stderr io.Writer, stdout io.Writer, pa case spec.long != "": longOptions = append(longOptions, spec) if spec.long == "version" { - hasVersionOption = true + // hasVersionOption = true } case spec.short != "": shortOptions = append(shortOptions, spec) @@ -52,7 +52,7 @@ func (p *Parser) WriteHelpForAutocomplete(stderr io.Writer, stdout io.Writer, pa for ancestor != nil { for _, spec := range ancestor.specs { if spec.long == "version" { - hasVersionOption = true + // hasVersionOption = true break } } @@ -60,15 +60,17 @@ func (p *Parser) WriteHelpForAutocomplete(stderr io.Writer, stdout io.Writer, pa ancestor = ancestor.parent } - if p.description != "" { - fmt.Fprintln(stderr, p.description) - } + /* + if p.description != "" { + fmt.Fprintln(stderr, p.description) + } - if !hasVersionOption && p.version != "" { - fmt.Fprintln(stderr, p.version) - } + if !hasVersionOption && p.version != "" { + fmt.Fprintln(stderr, p.version) + } - p.WriteUsageForSubcommand(stderr, subcommand...) + p.WriteUsageForSubcommand(stderr, subcommand...) + */ // write the list of positionals if len(positionals) > 0 { @@ -87,34 +89,37 @@ func (p *Parser) WriteHelpForAutocomplete(stderr io.Writer, stdout io.Writer, pa for _, spec := range longOptions { p.printOption(stderr, spec) //jwc - if strings.HasPrefix(spec.long, partial) { - automatch = append(automatch, "--"+spec.long) + tmp := "--" + spec.long + if strings.HasPrefix(tmp, partial) { + automatch = append(automatch, tmp) } } } - // write the list of global options - if len(globals) > 0 { - fmt.Fprint(stderr, "\nGlobal options:\n") - for _, spec := range globals { - p.printOption(stderr, spec) + /* + // write the list of global options + if len(globals) > 0 { + fmt.Fprint(stderr, "\nGlobal options:\n") + for _, spec := range globals { + p.printOption(stderr, spec) + } } - } - // write the list of built in options - p.printOption(stderr, &spec{ - cardinality: zero, - long: "help", - short: "h", - help: "display this help and exit", - }) - if !hasVersionOption && p.version != "" { + // write the list of built in options p.printOption(stderr, &spec{ cardinality: zero, - long: "version", - help: "display version and exit", + long: "help", + short: "h", + help: "display this help and exit", }) - } + if !hasVersionOption && p.version != "" { + p.printOption(stderr, &spec{ + cardinality: zero, + long: "version", + help: "display version and exit", + }) + } + */ // write the list of environment only variables if len(envOnlyOptions) > 0 { @@ -145,6 +150,9 @@ func (p *Parser) WriteHelpForAutocomplete(stderr io.Writer, stdout io.Writer, pa } else { // writes out the shell autocomplete matches if len(automatch) > 0 { + // fmt.Fprintf(os.Stderr, "%s\n", strings.Join(automatch, " ")) + // fmt.Fprintf(os.Stderr, "%s\n", strings.Join(automatch, " ")) + // fmt.Fprintf(os.Stderr, "\n") fmt.Fprintf(stdout, "%s", strings.Join(automatch, " ")) } } |
