Skip to content

Instantly share code, notes, and snippets.

@wbashir
Created April 18, 2015 00:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wbashir/69472b30327fff382635 to your computer and use it in GitHub Desktop.
Save wbashir/69472b30327fff382635 to your computer and use it in GitHub Desktop.
Do Complete func
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