From f755f34a9d4fcd60bc06844e5d81d2b174d7b889 Mon Sep 17 00:00:00 2001 From: Hans Raaf Date: Fri, 5 May 2023 00:06:33 +0200 Subject: [PATCH] A try to make completion work better with default commands. --- app.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/app.go b/app.go index 5cb8eea..55c289d 100644 --- a/app.go +++ b/app.go @@ -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 {