Skip to content

Instantly share code, notes, and snippets.

@zeekay
Created April 27, 2018 12:28
Show Gist options
  • Save zeekay/7930504db13cb291ae0fc14bbafb68ec to your computer and use it in GitHub Desktop.
Save zeekay/7930504db13cb291ae0fc14bbafb68ec to your computer and use it in GitHub Desktop.
import sys
def complete(argv, parser):
"""Return completions for commandline."""
if not argv[1:]:
return
if not argv[1] == 'complete':
return
# Generate list of command:descriptions
completions = []
commands = parser.format_help().split('\n')[8:-5]
for cmd in commands:
k, v = cmd.strip().split(None, 1)
completions.append("{0}:{1}".format(k, v))
print('\n'.join(completions))
sys.exit(0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment