Skip to content
Myr

Fixed generated bash complete function name. This fixes #221

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Armin Ronacher · committed by Armin Ronacher · parent 9da1791 · Browse files · 3 files+14 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+14 added−1 removed

  • tests:+7 added−0 removed
  • other:+7 added−1 removed

3 files+14 added−1 removed

modified:click/_bashcomplete.py+5 added-1 removed
1import os2import re3from .utils import echo4from .parser import split_arg_string5from .core import MultiCommand, Option6
8 unmodified lines
1516complete -F %(complete_func)s -o default %(script_names)s17'''1819_invalid_ident_char_re = re.compile(r'[^a-zA-Z0-9_]')202122def get_completion_script(prog_name, complete_var):23 cf_name = _invalid_ident_char_re.sub('', prog_name.replace('-', '_'))24 return (COMPLETION_SCRIPT % {21 'complete_func': '_%s_completion' % prog_name,25 'complete_func': '_%s_completion' % cf_name,26 'script_names': prog_name,27 'autocomplete_var': complete_var,28 }).strip() + ';'29
49 unmodified lines
modified:tests/test_compat.py+7 added
13 unmodified lines
14 result = runner.invoke(cli, ['--foo', 'wat'])15 assert result.exit_code == 016 assert 'WAT' in result.output17 assert 'Invoked legacy parameter callback' in result.output181920def test_bash_func_name():21 from click._bashcomplete import get_completion_script22 script = get_completion_script('foo-bar baz_blah', '_COMPLETE_VAR').strip()23 assert script.startswith('_foo_barbaz_blah_completion()')24 assert '_COMPLETE_VAR=complete $1' in script
modified:CHANGES+2 added
24 unmodified lines
25- Fix a bug when showing the default for multiple arguments.26- Added support for custom subclasses to `option` and `argument`.27- Fix bug in ``clear()`` on Windows when colorama is installed.28- Reject ``nargs=-1`` for options properly. Options cannot be variadic.29- Fixed an issue with bash completion not working properly for commands with30 non ASCII characters or dashes.3132Version 3.333-----------34
176 unmodified lines