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

Add framework for dynamic tab completions #883

Closed
wants to merge 5 commits into from

Conversation

PapaCharlie
Copy link
Contributor

By setting the COBRA_FLAG_COMPLETION environment variable, the normal execution path of the command
is short circuited, and instead the function registered by MarkCustomFlagCompletion is executed.

All flags other than the one being completed get parsed according to whatever type they are defined
as, but the flag being completed is parsed as a raw string and passed into the custom compeltion.

@CLAassistant
Copy link

CLAassistant commented Jun 12, 2019

CLA assistant check
All committers have signed the CLA.

@PapaCharlie PapaCharlie force-pushed the master branch 4 times, most recently from 99cb4de to 24896de Compare June 19, 2019 21:59
@PapaCharlie
Copy link
Contributor Author

The failing tests are being fixed in #889. After it is checked in, this commit will be all green

By setting the COBRA_FLAG_COMPLETION environment variable, the normal execution path of the command
is short circuited, and instead the function registered by `MarkCustomFlagCompletion` is executed.

All flags other than the one being completed get parsed according to whatever type they are defined
as, but the flag being completed is parsed as a raw string and passed into the custom compeltion.
The breakage was caused by the change at line 336, which changed the completion from
```
--option[Help message]:
```
to
```
--option[Help message]:option
```
Semantically this does not change the behavior of the completion, but it does tell zsh to tell you
which flag it is currently completing
It turns out that zsh will simply use the elements of an array as the parameters when referenced in
the shell without quotes
```
% cat t.py
import sys
print sys.argv

% typeset -a args
% args+=("./t.py")
% args+=("123
321")
% $args
['./t.py', '123\n321']
```
Also attempt to standardize the bash and zsh implementations

Next up: tests!
@github-actions
Copy link

This PR is being marked as stale due to a long period of inactivity

@marckhouzam
Copy link
Collaborator

This is pretty cool!
But Cobra 1.0 added support for Go completions not only for flags but also for arguments, which I believe supersedes this PR.
See
https://github.com/spf13/cobra/blob/master/bash_completions.md#1-custom-completions-of-flags-written-in-go
and
https://github.com/spf13/cobra/blob/master/bash_completions.md#1-custom-completions-of-nouns-written-in-go

I believe this can be closed.

@PapaCharlie
Copy link
Contributor Author

Hey Marc! Let me take a look at the new features, I'll close this for now and open a new branch on top of 1.0 in case I find anything missing, but it looks like I won't have to

@PapaCharlie PapaCharlie closed this May 5, 2020
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

Successfully merging this pull request may close these issues.

None yet

3 participants