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

Added templates that are compatible with click 8 #45

Merged
merged 1 commit into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions click_completion/bash-click8.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eval "$(_{{prog_name.upper()}}_COMPLETE=bash_source {{prog_name}})"
11 changes: 10 additions & 1 deletion click_completion/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from __future__ import print_function, absolute_import

import distutils
import os
import re
import shlex
Expand Down Expand Up @@ -303,7 +304,15 @@ def get_code(shell=None, prog_name=None, env_name=None, extra_env=None):
env_name = env_name or '_%s_COMPLETE' % prog_name.upper().replace('-', '_')
extra_env = extra_env if extra_env else {}
env = Environment(loader=FileSystemLoader(os.path.dirname(__file__)))
template = env.get_template('%s.j2' % shell.name)

click_ver = distutils.version.StrictVersion(click.__version__)
click8_ver = distutils.version.StrictVersion('8.0.0')
if click_ver >= click8_ver:
template_name = '%s-click8.j2'
else:
template_name = '%s.j2'
template = env.get_template(template_name % shell.name)

return template.render(prog_name=prog_name, complete_var=env_name, extra_env=extra_env)


Expand Down
1 change: 1 addition & 0 deletions click_completion/fish-click8.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
eval (env _{{prog_name.upper()}}_COMPLETE=fish_source {{prog_name}})
7 changes: 7 additions & 0 deletions click_completion/zsh-click8.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#compdef {{prog_name}}
_{{prog_name}}() {
eval "$(_{{prog_name.upper()}}_COMPLETE=zsh_source {{prog_name}})"
}
if [[ "$(basename -- ${(%):-%x})" != "_{{prog_name}}" ]]; then
compdef _{{prog_name}} {{prog_name}}
fi