Skip to content
Myr

Moved bashcomplete into an internal module by name.

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 ce616c9 · Browse files · 3 files+75 added−75 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+75 added−75 removed

  • other:+75 added−75 removed

3 files+75 added−75 removed

added:click/_bashcomplete.py+74 added
1import os2from click.utils import echo3from click.parser import split_arg_string4from click.core import MultiCommand, Option567COMPLETION_SCRIPT = '''8%(complete_func)s() {9 COMPREPLY=( $( COMP_WORDS="${COMP_WORDS[*]}" \\10 COMP_CWORD=$COMP_CWORD \\11 %(autocomplete_var)s=complete $1 ) )12 return 013}1415complete -F %(complete_func)s -o default %(script_names)s16'''171819def get_completion_script(prog_name, complete_var):20 return (COMPLETION_SCRIPT % {21 'complete_func': '_%s_completion' % prog_name,22 'script_names': prog_name,23 'autocomplete_var': complete_var,24 }).strip() + ';'252627def resolve_ctx(cli, prog_name, args):28 ctx = cli.make_context(prog_name, args, resilient_parsing=True)29 while ctx.args and isinstance(ctx.command, MultiCommand):30 cmd = ctx.command.get_command(ctx, ctx.args[0])31 if cmd is None:32 return None33 ctx = cmd.make_context(ctx.args[0], ctx.args[1:], parent=ctx,34 resilient_parsing=True)35 return ctx363738def do_complete(cli, prog_name):39 cwords = split_arg_string(os.environ['COMP_WORDS'])40 cword = int(os.environ['COMP_CWORD'])41 args = cwords[1:cword]42 try:43 incomplete = cwords[cword]44 except IndexError:45 incomplete = ''4647 ctx = resolve_ctx(cli, prog_name, args)48 if ctx is None:49 return True5051 choices = []52 if incomplete and not incomplete[:1].isalnum():53 for param in ctx.command.params:54 if not isinstance(param, Option):55 continue56 choices.extend(param.opts)57 choices.extend(param.secondary_opts)58 elif isinstance(ctx.command, MultiCommand):59 choices.extend(ctx.command.list_commands(ctx))6061 for item in choices:62 if item.startswith(incomplete):63 echo(item)6465 return True666768def bashcomplete(cli, prog_name, complete_var, complete_instr):69 if complete_instr == 'source':70 echo(get_completion_script(prog_name, complete_var))71 return True72 elif complete_instr == 'complete':73 return do_complete(cli, prog_name)74 return False
deleted:click/bashcomplete.py-74 removed
1import os2from click.utils import echo3from click.parser import split_arg_string4from click.core import MultiCommand, Option567COMPLETION_SCRIPT = '''8%(complete_func)s() {9 COMPREPLY=( $( COMP_WORDS="${COMP_WORDS[*]}" \\10 COMP_CWORD=$COMP_CWORD \\11 %(autocomplete_var)s=complete $1 ) )12 return 013}1415complete -F %(complete_func)s -o default %(script_names)s16'''171819def get_completion_script(prog_name, complete_var):20 return (COMPLETION_SCRIPT % {21 'complete_func': '_%s_completion' % prog_name,22 'script_names': prog_name,23 'autocomplete_var': complete_var,24 }).strip() + ';'252627def resolve_ctx(cli, prog_name, args):28 ctx = cli.make_context(prog_name, args, resilient_parsing=True)29 while ctx.args and isinstance(ctx.command, MultiCommand):30 cmd = ctx.command.get_command(ctx, ctx.args[0])31 if cmd is None:32 return None33 ctx = cmd.make_context(ctx.args[0], ctx.args[1:], parent=ctx,34 resilient_parsing=True)35 return ctx363738def do_complete(cli, prog_name):39 cwords = split_arg_string(os.environ['COMP_WORDS'])40 cword = int(os.environ['COMP_CWORD'])41 args = cwords[1:cword]42 try:43 incomplete = cwords[cword]44 except IndexError:45 incomplete = ''4647 ctx = resolve_ctx(cli, prog_name, args)48 if ctx is None:49 return True5051 choices = []52 if incomplete and not incomplete[:1].isalnum():53 for param in ctx.command.params:54 if not isinstance(param, Option):55 continue56 choices.extend(param.opts)57 choices.extend(param.secondary_opts)58 elif isinstance(ctx.command, MultiCommand):59 choices.extend(ctx.command.list_commands(ctx))6061 for item in choices:62 if item.startswith(incomplete):63 echo(item)6465 return True666768def bashcomplete(cli, prog_name, complete_var, complete_instr):69 if complete_instr == 'source':70 echo(get_completion_script(prog_name, complete_var))71 return True72 elif complete_instr == 'complete':73 return do_complete(cli, prog_name)74 return False
modified:click/core.py+1 added-1 removed
22 unmodified lines
23 complete_instr = os.environ.get(complete_var)24 if not complete_instr:25 return2627 from click.bashcomplete import bashcomplete27 from click._bashcomplete import bashcomplete28 if bashcomplete(cmd, prog_name, complete_var, complete_instr):29 sys.exit(1)3031
1222 unmodified lines