(flag *pflag.Flag, toComplete string)
| 594 | } |
| 595 | |
| 596 | func getFlagNameCompletions(flag *pflag.Flag, toComplete string) []Completion { |
| 597 | if nonCompletableFlag(flag) { |
| 598 | return []Completion{} |
| 599 | } |
| 600 | |
| 601 | var completions []Completion |
| 602 | flagName := "--" + flag.Name |
| 603 | if strings.HasPrefix(flagName, toComplete) { |
| 604 | // Flag without the = |
| 605 | completions = append(completions, CompletionWithDesc(flagName, flag.Usage)) |
| 606 | |
| 607 | // Why suggest both long forms: --flag and --flag= ? |
| 608 | // This forces the user to *always* have to type either an = or a space after the flag name. |
| 609 | // Let's be nice and avoid making users have to do that. |
| 610 | // Since boolean flags and shortname flags don't show the = form, let's go that route and never show it. |
| 611 | // The = form will still work, we just won't suggest it. |
| 612 | // This also makes the list of suggested flags shorter as we avoid all the = forms. |
| 613 | // |
| 614 | // if len(flag.NoOptDefVal) == 0 { |
| 615 | // // Flag requires a value, so it can be suffixed with = |
| 616 | // flagName += "=" |
| 617 | // completions = append(completions, CompletionWithDesc(flagName, flag.Usage)) |
| 618 | // } |
| 619 | } |
| 620 | |
| 621 | flagName = "-" + flag.Shorthand |
| 622 | if len(flag.Shorthand) > 0 && strings.HasPrefix(flagName, toComplete) { |
| 623 | completions = append(completions, CompletionWithDesc(flagName, flag.Usage)) |
| 624 | } |
| 625 | |
| 626 | return completions |
| 627 | } |
| 628 | |
| 629 | func completeRequireFlags(finalCmd *Command, toComplete string) []Completion { |
| 630 | var completions []Completion |
no test coverage detected