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

molecule zsh completion support is broken #2028

Closed
codequokka opened this issue May 6, 2019 · 8 comments · Fixed by #3118
Closed

molecule zsh completion support is broken #2028

codequokka opened this issue May 6, 2019 · 8 comments · Fixed by #3118

Comments

@codequokka
Copy link

Issue Type

  • Bug report

Molecule and Ansible details

ansible --version && molecule --version

ansible 2.7.10
  config file = None
  configured module search path = ['/Users/nbchk/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /Users/nbchk/.ghq/github.com/codequokka/ansible-role-pypro3/.venv/lib/python3.7/site-packages/ansible
  executable location = /Users/nbchk/.ghq/github.com/codequokka/ansible-role-pypro3/.venv/bin/ansible
  python version = 3.7.3 (default, Mar 27 2019, 09:23:15) [Clang 10.0.1 (clang-1001.0.46.3)]
molecule, version 2.20.1

Molecule installation method (one of):

  • pip

Ansible installation method (one of):

  • pip

Detail any linters or test runners used:

  • None

Desired Behavior

As fish and bash completion support, zsh also should have same one.

  • fish
bash-3.2$ eval "$(_MOLECULE_COMPLETE=source molecule)"                                                                                                      bash-3.2$  . /Users/nbchk/.ghq/github.com/codequokka/ansible-role-pypro3/.venv/bin/activate
bash-3.2$ molecule l
lint   list   login
  • bash
❯ eval (env _MOLECULE_COMPLETE=source-fish molecule)
❯ molecule list
lint  (Lint the role.)  list  (Lists status of instances.)

Actual Behaviour

Zsh has no completion in pressing tab.

% eval "$(_MOLECULE_COMPLETE=source_zsh molecule)"
% molecule l

@codequokka codequokka added the bug label May 6, 2019
@gundalow gundalow added enhancement and removed bug labels May 6, 2019
@gundalow
Copy link
Contributor

gundalow commented May 6, 2019

@codequokka Thanks for the suggestion, I've changed this to enhancement, rather than bug.

In Ansible this was done by using argparse ansible/ansible#50610

@decentral1se
Copy link
Contributor

👍 👍 👍

@codequokka
Copy link
Author

@gundalow Thank you for replying.
Molecule uses click and click-completion packages to parse command line args.
These packages are supposed to generate completion script for bash, zsh and fish.
So, I don't know why it doesn't generate completion script only for zsh.
Do you know the reason why?

@Lirt
Copy link
Contributor

Lirt commented May 22, 2019

It works in my case, however it doesn't complete arguments for commands (this is intended I guess).

# ZSH version
zsh --version
zsh 5.6.2 (x86_64-redhat-linux-gnu)

# Molecule version
molecule --version
molecule, version 2.20.1

# Autocomplete commands starting on `l`
molecule l<TAB>
lint   -- Lint the role.
list   -- Lists status of instances.
login  -- Log in to one instance.

# Autocomplete arguments for command `test`
molecule test<TAB>
Completing file
/etc /home ...

Edit:
I used eval "$(_MOLECULE_COMPLETE=source molecule)"

@decentral1se
Copy link
Contributor

Oh nice, can you confirm @codequokka?

@codequokka
Copy link
Author

@Lirt, @decentral1se

It works!
but basename error happens

$ eval "$(_MOLECULE_COMPLETE=source molecule)"
basename: illegal option -- z
usage: basename string [suffix]
       basename [-a] [-s suffix] string [...]

$ molecule l<TAB>
lint   -- Lint the role.
list   -- Lists status of instances.
login  -- Log in to one instance.

I found this error is caused basename command has no '-z' option on macOS.

$ zsh --version
zsh 5.7.1 (x86_64-apple-darwin18.2.0)

$ basename -z
basename: illegal option -- z
usage: basename string [suffix]
       basename [-a] [-s suffix] string [...]                                                                                                                            

It seems to me that this workaround only uses bash completion script on zsh.
https://click.palletsprojects.com/en/7.x/bashcomplete/

For instance, to enable Bash completion for your foo-bar script, this is what you would need to put into your .bashrc:
eval "$(_FOO_BAR_COMPLETE=source foo-bar)"

For zsh users add this to your .zshrc:
eval "$(_FOO_BAR_COMPLETE=source_zsh foo-bar)"

So, I do not know this is the essential solution for this issue.

@ssbarnea ssbarnea changed the title Is there zsh completion support? molecule zsh completion support is broken Jul 2, 2019
@ssbarnea ssbarnea self-assigned this Jul 2, 2019
@rbellamy
Copy link

Just tried eval $(register-python-argcomplete molecule) in zsh and got nothing, but eval "$(_MOLECULE_COMPLETE=source molecule)" worked well.

@ssbarnea
Copy link
Member

I can only confirm that completion does not work for me on zsh/macos with either of the documented commands, I endup gettin something like (eval):1: command not found: --

As I do not have time to dig into this I will be more than happy to review and manually test a PR that is fixing it.

I suspect is has something to do with the first line out debug output which looks like:

--> Found config file /Users/ssbarnea/.config/molecule/config.yml

Maybe this is where the -- comes from?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants