diff options
Diffstat (limited to 'complete.go')
| -rw-r--r-- | complete.go | 74 |
1 files changed, 35 insertions, 39 deletions
diff --git a/complete.go b/complete.go index 5002b3d..31a5398 100644 --- a/complete.go +++ b/complete.go @@ -18,9 +18,9 @@ type Complete struct { } func (p *Parser) WriteHelpForAutocompleteArgv() error { - fmt.Fprintln(argvpb.Stderr, "") - fmt.Fprintf(argvpb.Stderr, "go-args.WriteHelpForAutocompleteArgv() not finished") - fmt.Fprintln(argvpb.Stderr, "arg.ParseFlagsArgv()", argvpb.PB.Real) + fmt.Fprintln(argvpb.Stddbg, "") + fmt.Fprintf(argvpb.Stddbg, "go-args.WriteHelpForAutocompleteArgv() not finished") + fmt.Fprintln(argvpb.Stddbg, "arg.ParseFlagsArgv()", argvpb.PB.Real) return nil } @@ -28,7 +28,7 @@ func (p *Parser) WriteHelpForAutocompleteArgv() error { // most shell autocomplete behavior usually wants things that way func (p *Parser) WriteHelpForAutocomplete(partialOld string, subcommand ...string) error { var automatch []string - fmt.Fprintf(argvpb.Stderr, "go-args.WriteHelpForAutocomplete() sub(%v)\n", subcommand) + fmt.Fprintf(argvpb.Stddbg, "go-args.WriteHelpForAutocomplete() sub(%v)\n", subcommand) // return errors.New("subcommand was nil") if p == nil { return errors.New("arg.Parser == nil") @@ -38,12 +38,12 @@ func (p *Parser) WriteHelpForAutocomplete(partialOld string, subcommand ...strin } cmd, err := p.lookupCommand(subcommand...) if err != nil { - fmt.Fprintf(argvpb.Stderr, "go-args.WriteHelpForAutocomplete() lookupCommand failed err(%v)\n", err) + fmt.Fprintf(argvpb.Stddbg, "go-args.WriteHelpForAutocomplete() lookupCommand failed err(%v)\n", err) return err } var positionals, longOptions, shortOptions, envOnlyOptions []*spec - // var hasVersionOption bool + var hasVersionOption bool for _, spec := range cmd.specs { switch { case spec.positional: @@ -51,7 +51,7 @@ func (p *Parser) WriteHelpForAutocomplete(partialOld string, subcommand ...strin case spec.long != "": longOptions = append(longOptions, spec) if spec.long == "version" { - // hasVersionOption = true + hasVersionOption = true } case spec.short != "": shortOptions = append(shortOptions, spec) @@ -67,7 +67,7 @@ func (p *Parser) WriteHelpForAutocomplete(partialOld string, subcommand ...strin for ancestor != nil { for _, spec := range ancestor.specs { if spec.long == "version" { - // hasVersionOption = true + hasVersionOption = true break } } @@ -75,17 +75,15 @@ func (p *Parser) WriteHelpForAutocomplete(partialOld string, subcommand ...strin ancestor = ancestor.parent } - /* - if p.description != "" { - fmt.Fprintln(stderr, p.description) - } + if p.description != "" { + fmt.Fprintln(argvpb.Stderr, p.description) + } - if !hasVersionOption && p.version != "" { - fmt.Fprintln(stderr, p.version) - } + if !hasVersionOption && p.version != "" { + fmt.Fprintln(argvpb.Stderr, p.version) + } - p.WriteUsageForSubcommand(stderr, subcommand...) - */ + p.WriteUsageForSubcommand(argvpb.Stderr, subcommand...) // write the list of positionals if len(positionals) > 0 { @@ -111,30 +109,28 @@ func (p *Parser) WriteHelpForAutocomplete(partialOld string, subcommand ...strin } } - /* - // 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(argvpb.Stderr, "\nGlobal options:\n") + for _, spec := range globals { + p.printOption(argvpb.Stderr, spec) } + } - // write the list of built in options - p.printOption(stderr, &spec{ + // write the list of built in options + p.printOption(argvpb.Stderr, &spec{ + cardinality: zero, + long: "help", + short: "h", + help: "display this help and exit", + }) + if !hasVersionOption && p.version != "" { + p.printOption(argvpb.Stderr, &spec{ cardinality: zero, - long: "help", - short: "h", - help: "display this help and exit", + long: "version", + help: "display version 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 { @@ -160,12 +156,12 @@ func (p *Parser) WriteHelpForAutocomplete(partialOld string, subcommand ...strin fmt.Fprintln(argvpb.Stderr, "\n"+p.epilogue) } - fmt.Fprintf(argvpb.Stderr, "go-args.WriteHelpForAutocomplete() got to the end automatch(%v)\n", automatch) + fmt.Fprintf(argvpb.Stddbg, "go-args.WriteHelpForAutocomplete() got to the end automatch(%v)\n", automatch) // writes out the shell autocomplete matches if len(automatch) > 0 { fmt.Fprintf(argvpb.Stdout, "%s", strings.Join(automatch, " ")) } else { - fmt.Fprintf(argvpb.Stdout, "automatchBlank") + // fmt.Fprintf(argvpb.Stdout, "automatchBlank") } return nil } |
