Skip to content

Commit

Permalink
Merge pull request #40 from metatexx/oderwat-better-completion
Browse files Browse the repository at this point in the history
A try to make completion work better with default commands.
  • Loading branch information
ripienaar authored May 5, 2023
2 parents bf73d70 + f755f34 commit 85bd32e
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion app.go
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,19 @@ func (a *Application) completionOptions(context *ParseContext) []string {

func (a *Application) generateBashCompletion(context *ParseContext) {
options := a.completionOptions(context)
fmt.Printf("%s", strings.Join(options, "\n"))
opt1String := strings.Join(options, "\n")

// Re-parse the command-line ignoring defaults to find what if we did not set defaults
context, _ = a.parseContext(true, context.rawArgs)
opt2String := strings.Join(a.completionOptions(context), "\n")
if opt1String == "" {
fmt.Printf("%s", opt2String)
} else if opt2String != opt1String {
fmt.Printf("%s\n%s", opt1String, opt2String)
} else {
fmt.Printf("%s", opt1String)
}

}

func envarTransform(name string) string {
Expand Down

0 comments on commit 85bd32e

Please sign in to comment.