Created
April 18, 2015 00:01
-
-
Save wbashir/69472b30327fff382635 to your computer and use it in GitHub Desktop.
Do Complete func
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://github.com/mitsuhiko/click/blob/master/click/_bashcomplete.py#L42 | |
def do_complete(cli, prog_name): | |
cwords = split_arg_string(os.environ['COMP_WORDS']) | |
cword = int(os.environ['COMP_CWORD']) | |
args = cwords[1:cword] | |
try: | |
incomplete = cwords[cword] | |
except IndexError: | |
incomplete = '' | |
ctx = resolve_ctx(cli, prog_name, args) | |
if ctx is None: | |
return True | |
choices = [] | |
if incomplete and not incomplete[:1].isalnum(): | |
for param in ctx.command.params: | |
if not isinstance(param, Option): | |
continue | |
choices.extend(param.opts) | |
choices.extend(param.secondary_opts) | |
elif isinstance(ctx.command, MultiCommand): | |
choices.extend(ctx.command.list_commands(ctx)) | |
for item in choices: | |
if item.startswith(incomplete): | |
echo(item) | |
return True |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment