Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enums() type doesn't tab complete #346

Open
stroopc-stripe opened this issue Jan 11, 2024 · 0 comments
Open

Enums() type doesn't tab complete #346

stroopc-stripe opened this issue Jan 11, 2024 · 0 comments

Comments

@stroopc-stripe
Copy link

stroopc-stripe commented Jan 11, 2024

When using an Enums() flag, I noticed that it doesn't tab complete like an Enum() does. This was unexpected since the only difference is that an Enums allows multiple values from the set to be provided

Steps to reproduce

Save as main.go

package main

import (
	"github.com/alecthomas/kingpin/v2"
)

var (
	noComplete = kingpin.Flag("does-not-complete", "this flag does not tab complete").Enums("foo", "bar")
	complete   = kingpin.Flag("completes", "this flag will tab complete").Enum("foo", "bar")
)

func main() {
	kingpin.Parse()
}

Then:

go mod init test-complete
go mod tidy
go build -o test-complete main.go
# use --completion-script-zsh if you're using zsh
eval "$(./test-complete --completion-script-bash)" 

# "foo" and "bar" won't show up as options
test-complete --does-not-complete <TAB>

# "foo" and "bar" show up as options
test-complete --completes <TAB>
bar foo

Workaround

Use HintOptions("foo", "bar") or HintAction(customFunc) when using an Enums type:

	nowCompletes = kingpin.Flag("does-not-complete", "this flag does not tab complete").HintOptions("foo", "bar").Enums("foo", "bar")

This works fine, but seems wholly unnecessary to repeat the values twice and means Enums still doesn't behave the way it is expected to.

@stroopc-stripe stroopc-stripe changed the title Enums flag type doesn't tab complete Enums() type doesn't tab complete Jan 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant