1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

wip: complete subcommands after bare flags

This commit is contained in:
Tom Whitwell
2023-10-15 11:13:06 +01:00
parent b91bcf373f
commit b147fbf557
2 changed files with 98 additions and 1 deletions

View File

@ -85,6 +85,24 @@ func Run(v string) int {
sort.Sort(cli.CommandsByName(commands))
app.Commands = commands
app.EnableBashCompletion = true
app.BashComplete = func(cCtx *cli.Context) {
// ripped from cli.DefaultCompleteWithFlags
var lastArg string
if len(os.Args) > 2 {
lastArg = os.Args[len(os.Args)-2]
}
if lastArg != "" {
if strings.HasPrefix(lastArg, "-") {
if !islastFlagComplete(lastArg, app.Flags) {
dnscontrolPrintFlagSuggestions(lastArg, app.Flags, cCtx.App.Writer)
return
}
}
}
dnscontrolPrintCommandSuggestions(app.Commands, cCtx.App.Writer)
}
if err := app.Run(os.Args); err != nil {
return 1
}