-
Notifications
You must be signed in to change notification settings - Fork 273
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
Auto completion for partial arguments #159
Comments
Sorry this took so long. Do you have a test case that can replicate this? |
Certainly, here's an example: package main
import "github.com/alecthomas/kingpin"
var (
arg = kingpin.Arg("arg", "").HintOptions("alpha", "bravo", "charlie")
input = arg.String()
)
func main() {
kingpin.Parse()
} If you run "go run main.go --completion-bash" it helpfully returns the list of hint options, but if you've already half typed one of the options, like "go run main.go alp --completion-bash" it can't auto-complete the remainder of your argument. I don't think this is a bug. Your documentation only states that auto-completion works for commands/subcommands and flags, but never makes any promises about arguments. I don't know if this is by design -- I can imagine a few reasons that this would be difficult to implement -- but it would definitely be very nice. This argument autocompletion does work in the bash for existing file or directory arguments, but I think that's behaviour programmed into bash and not kingpin. Thanks! |
This is occurring due to several factors:
If the latter were possible, I think this could be solved, but without that information I don't think it can be fixed. Any thoughts? |
This ambiguity does not exist for commands or flags, because they either "match" or "do not match". |
I can see what you mean. I presume that the arguments to your script are default bash behaviour, meaning that we can't adjust it to include that distinction between I think there surely must be a solution, because it felt like a missing feature when I encountered it, so I imagine that I've seen it working somewhere before. Unfortunately I cannot think what the answer is. Is there a way to define values that should not be accepted? Kind of like the opposite of a ".HintOptions" function. Instead of telling Kingpin what values to suggest, provide a function or filter kingpin should call to check the argument and see if it works? Perhaps the functionality could be integrated seamlessly by calling the PreAction for each element during the autocompletion. PreAction could validate arguments and return an error if it fails, and if it fails then the autocompletion logic would know that the argument has not been accepted and can therefore continue trying to match using the current value as a prefix? |
Turns out that this should actually be possible (from a shell perspective). |
Ah. Well, that's all I can contribute I'm afraid. I hope the feature finds its way in someday. I do think it would be a fantastic quality-of-life improvement. |
I'm trying to get bash auto completion working for my string arguments based on hints that I'm correctly defining in my app.
"myapp --completion-bash" is correctly returning a list of custom hints I've specified for the argument.
But "myapp a --completion-bash" does not return a subset of the previous list based on which ones match the prefix 'a'. This means that bash won't use tab to auto complete the argument.
Is there a way to achieve the desired behaviour?
The text was updated successfully, but these errors were encountered: