-
-
Notifications
You must be signed in to change notification settings - Fork 267
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
Complete bug IDs where appropriate #531
Conversation
THIS IS AWESOME!
I think the ZSH completion code in cobra does support yet this new completion framework. I think it will work eventually, without any changes required on the git-bug side.
I think the
Hmmm dunno. Even with changing |
I'll push a minor fix - completions don't work yet for a command like |
7fa0ce0
to
df1db38
Compare
Yeah,
Ok, I'll report that. Looks like there are some other fish-specific issues over there that need addressing, I'll take care of those. |
15cd8de
to
8d23da6
Compare
Ok, I've extended this to all subcommands and flags. This should cover all subcommands. In fish, |
doc/gen_docs.go
Outdated
@@ -21,22 +20,15 @@ func main() { | |||
"Markdown": genMarkdown, | |||
} | |||
|
|||
var wg sync.WaitGroup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why are you removing that? Fast build is nice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See the commit message - without this commit I usually get a data race when running make
.
I didn't really investigate what the real fix should be. Do you think we should use global variables for the Cobra commands?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's the opposite actually. Cobra use a global map here. This global map is shared even if multiple independent root command are created.
It looks like it could be easily solved in cobra though ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, not really easy but doable
I was going to report the issue to cobra but I see you did it already ;) I made it into its own issue though, with some extra possible solutions: spf13/cobra#1320 |
Let's wait a bit to see if something is moving on the cobra side. We'll merge either way at the very last before the next version, don't worry. |
8d23da6
to
a1db6ce
Compare
The cobra issue got resolved upstream, there is hope! spf13/cobra#1438 |
cobra bump is here ... need to be tested and then we can add it in ?! |
ok tested and bump is in @krobelus can you rebase? |
a1db6ce
to
b2effa9
Compare
hey hello, I finally get more and more time to work on this project, sorry for the crazy long delay. I've been trying out this PR to see if everything was fine. The build process got fixed indeed but ... the completion doesn't work for me. It might be because of the cobra upgrade as they made some related change, but they claim to have kept backward compatibility. I've looked around and everything seems fine. Any idea? It's probably something silly. |
It's also possible that I'm just using it wrong. |
b2effa9
to
715a8eb
Compare
fish and bash completions seem to work (although bash only works with |
@krobelus there is this little bash thing that should map Maybe it's not being exported as part of the completion script anymore? |
I tried a few things, I can't get it to work with bash (I didn't try the others):
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm trying to figure out what's happening. The following actually returns something that looks ok:
: git-bug __complete select 68
681b740 sqdsqdqsdqsdsq
e4c9831 sqdjlksqdsdiqolz
:0
Completion ended with directive: ShellCompDirectiveDefault
And yet, when I try git-bug select 68^I
nothing happens.
commands/helper_completion.go
Outdated
completions[i] = bridge + "\t" + "Bridge" | ||
} | ||
|
||
return completions, cobra.ShellCompDirectiveDefault |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Out of curiosity, why not ShellCompDirectiveNoFileComp
here?
commands/helper_completion.go
Outdated
|
||
func completeBug(env *Env) validArgsFunction { | ||
return func(cmd *cobra.Command, args []string, toComplete string) (completions []string, directives cobra.ShellCompDirective) { | ||
if len(args) > 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be nice to complete even if len(args) == 0
. That's one of the problem I had, I tried to complete git-bug select
which didn't work as your code returns an empty array.
If you did that to avoid returning thousands of completion proposition, maybe we should have an arbitrary limit?
commands/helper_completion.go
Outdated
allIds := env.backend.AllBugsIds() | ||
bugExcerpt := make([]*cache.BugExcerpt, len(allIds)) | ||
for i, id := range allIds { | ||
var err error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what about filtering here to only output the ones with toComplete
as prefix?
I found the root cause, |
+func completeBug(env *Env) validArgsFunction {
+ return func(cmd *cobra.Command, args []string, toComplete string) (completions []string, directives cobra.ShellCompDirective) {
+ if len(args) > 0 {
It'd be nice to complete even if `len(args) == 0`.
That's one of the problem I had, I tried to complete `git-bug select` which didn't work as your code returns an empty array.
Right, you found another bug!
I'm afraid I don't have much time these days, so if someone wants to take over go ahead.
If you did that to avoid returning thousands of completion proposition, maybe we should have an arbitrary limit?
I think shells will already filter completions, so I don't think we need to.
In particular, fish sometimes shows all completions for which the commandline's token is a subsequence of the completion.
So if we filter, we might actually lose some valid completions, and I don't think there's a need filter unless we are returning many megabytes of data.
|
Complete bug IDs, bridges, users, labels where appropriate. This works in bash and fish. ZSH is not yet supported by Cobra. In fish, descriptions (the part of a completion after the "\t") are shown as completion label, and can be searched with Ctrl+S. Reproduce with fish -C 'source misc/fish_completion/git-bug' git bug select ^I (tested with fish version 3.3.1) Also works with bash, but only for "git-bug" (with the dash) bash --rcfile <(echo source misc/bash_completion/git-bug) git-bug select ^I Closes git-bug#493
dcb3965
to
beffeaa
Compare
beffeaa
to
3d534a7
Compare
This completes bug IDs in bash and fish. I haven't gotten completions to work in zsh.
In fish, the bug titles are shown as completion label, and can be searched for.
I don't know if/how other shells can show the completion label.
Maybe they don't use "\t" as separator but it seems to do no harm.
The interface does not yet seem ideal because sometimes subcommands and
bug IDs are both valid. Since there can be lots of bug IDs, they overshadow
the subcommands.
I wonder if instead of
we should use
or if there's some other way to avoid ambiguity.
If that doesn't work out, fish has a -k/--keep-order flag, so subcommand
completions can be listed before bug IDs, but that's neither portable nor
a pretty solution.
Part of #493