-
Notifications
You must be signed in to change notification settings - Fork 72
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
Add support for completing short flags (-x) #127
Comments
Hey Chris,
Can you elaborate more on the ecosystem that you are using? How the
completion is invoked? What OS? What shell? How is the complete command
installed in the shell?
…On Mon, Oct 5, 2020 at 7:20 AM Chris ***@***.***> wrote:
I have a setup like so:
Flags: map[string]complete.Predictor{
"o": predict.Nothing,
"upload-pack": predict.Nothing,
...
}
Now when I type a command like <cmd> -- [TAB] I see the below
[image: Screen Shot 2020-10-05 at 12 15 48 AM]
<https://user-images.githubusercontent.com/6971318/95039905-0f876e80-06a0-11eb-9492-1753146d4243.png>
I would expect to only see the long flags
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#127>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAHAN7WAAMCUG6ZA3NDOBYTSJFCRDANCNFSM4SEFVFVA>
.
|
Ecosystem: V2 Here's the completion file if you're curious: |
I see, |
So if I understand correctly, there isn't a good workaround for this unless Go changes the way it handles flags. I'm probably reading the code wrong but couldn't |
Not exactly, this library is not directly related to Go's flags, but when I wrote it, I kept Go's flags idioms in mind. It makes sense to allow single-dash flags here, as an option. One issue with adding this feature, is that the Completer interface has a ListFlags method that returns all flag names, and does not distinguish between single and double dash flags. And changes to this interface will break the library's API (e.g. return a list of some flag type instead of a list of strings, or add another method that returns the list of single dash flags...).
In the linked code, the completion remembers how many flags there were, and compare the flag names, and then output the number of dashes that the user entered plus the flag name. Since both single and double dashes are allowed, it tries to complete all available flags. |
Actually, there is another option, we can create an optional interface, in which we can add a function, for example |
Cool depending on how much time I have, I could probably help out 👍 |
Hey @posener I wrote up a proof of concept here chriswalz@b376a83 Some notes:
|
Hey,
|
|
@posener hey please check out this PR #129. The idea is that instead of this: You use this to enable the old way of unix style (without breaking backwards compatibility): Currently these two tests are failing and I'm not quite sure why
Seems to be something related to |
Hi, sorry for keeping you waiting with the PR. There is more into it, i think. I'm not sure that the current behavior is wrong - From what I see here, a single dash can be followed by multiple single dash flags, so we might want to support this as well? However, this behavior might confuse users, for example, what happens when there is a short flag that should also get a value? Or, do we want to support short flags, but not support getting multiple short flags? The most elegant way I can see this being somehow solved is by extending the // ShortFlagger is an optional interface for
type ShortFlager interface {
ListShortFlags() []rune
} Then, add to the But again, I'm not sure that having this option will not confuse users more than it will benefit. I really don't see the harm in the current implementation. How is this a deal breaker for you? Why is it so bad that the current completion will allow both Thanks! |
I'm not that familiar with optional interfaces but I believe I understand what you mean. For context I'm partially wrapping |
I have a setup like so:
Now when I type a command like
<cmd> --
[TAB] I see the belowI would expect to only see the long flags
The text was updated successfully, but these errors were encountered: