base functionality

- core CLI options + extra CLI options
- remove options with no CLI support
This commit is contained in:
Nishant Rodrigues 2020-04-25 22:16:37 +05:30 committed by Casper da Costa-Luis
parent 5f733eea79
commit 27e9338f24
No known key found for this signature in database
GPG Key ID: 986B408043AE090D
1 changed files with 37 additions and 2 deletions

View File

@ -6,13 +6,48 @@ import tqdm
import tqdm.cli
from io import open as io_open
from os import path
import re
def doc2opt(doc):
"""
doc : str, document to parse
"""
options = ['--' + i.strip(' :') for i in re.findall(r'\w+ :', doc)]
return options
# CLI options
options = ['-h', '--help', '-v', '--version']
options += doc2opt(tqdm.tqdm.__init__.__doc__)
options += doc2opt(tqdm.cli.CLI_EXTRA_DOC)
# Remove options without CLI support
no_support = ['--' + i for i in tqdm.cli.UNSUPPORTED_OPTS]
# TODO: Check and remove option `name`
no_support += ['--name']
options = list(set(options) - set(no_support))
src_dir = path.abspath(path.dirname(__file__))
completion = u"""\
#!/usr/bin/env bash
# TODO: programatically generate based on tqdm.tqdm/tqdm.cli
"""
_tqdm()
{{
local cur prv
cur="${{COMP_WORDS[COMP_CWORD]}}"
prv="${{COMP_WORDS[COMP_CWORD - 1]}}"
case ${{prv}} in
"--log")
COMPREPLY=($(compgen -W 'CRITICAL FATAL ERROR WARN WARNING INFO DEBUG NOTSET' -- ${{cur}}))
;;
*)
COMPREPLY=($(compgen -W '{0}' -- ${{cur}}))
;;
esac
}}
complete -F _tqdm tqdm
""".format(' '.join(options))
if __name__ == "__main__":
fncompletion = path.join(path.dirname(src_dir), 'tqdm', 'completion.sh')