alecthomas / kingpin

CONTRIBUTIONS ONLY: A Go (golang) command line and flag parser
MIT License
3.5k stars 273 forks source link

Honour -- delimiter in autocompletion #316

Closed jpcoenen closed 4 years ago

jpcoenen commented 4 years ago

If a -- argument is passed, from then on only arguments should be parsed. This is already handled correctly in most places, but autocompleting did not honour this yet.

Example

package main

import "github.com/alecthomas/kingpin"

func main(){
   kingpin.Arg("arg1", "").String()
   kingpin.Flag("flag1", "").String()
   kingpin.Flag("flag2", "").String()
   kingpin.Parse()
}

If this following command is executed:

go run main.go --completion-bash an-argument --flag1 --  --

We expect not to get a suggestion for any of the flags of the command because the -- argument signals that all arguments were provided. However, on the current master, the result is:

$ go run main.go --completion-bash an-argument --flag1 --  --
--help
--flag1
--flag2

If there is a more elegant solution to achieve this (without a big refactor), I'm happy to hear it.