From 17482374a5dbcab53ce3696a462e6c659314cd92 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Sat, 5 Aug 2023 22:15:53 +0100 Subject: [PATCH] cli: fix & update completion --- .meta/mkcompletion.py | 13 ++++----- tqdm/cli.py | 66 +++++++++++++++++++++---------------------- tqdm/tqdm.1 | 6 ++-- 3 files changed, 40 insertions(+), 45 deletions(-) diff --git a/.meta/mkcompletion.py b/.meta/mkcompletion.py index 387bd307..130c2f80 100644 --- a/.meta/mkcompletion.py +++ b/.meta/mkcompletion.py @@ -3,10 +3,9 @@ Auto-generate tqdm/completion.sh from docstrings. """ import re import sys -from io import open as io_open -from os import path +from pathlib import Path -sys.path.insert(0, path.dirname(path.dirname(__file__))) +sys.path.insert(0, str(Path(__file__).parent.parent)) import tqdm # NOQA import tqdm.cli # NOQA @@ -27,13 +26,12 @@ def doc2opt(doc, user_input=True): # CLI options options = {'-h', '--help', '-v', '--version'} options_input = set() -for doc in (tqdm.tqdm.__init__.__doc__, tqdm.cli.CLI_EXTRA_DOC): +for doc in (tqdm.tqdm.__doc__, tqdm.cli.CLI_EXTRA_DOC): options.update(doc2opt(doc, user_input=False)) options_input.update(doc2opt(doc, user_input=True)) options.difference_update('--' + i for i in ('name',) + tqdm.cli.UNSUPPORTED_OPTS) options_input &= options options_input -= {"--log"} # manually dealt with -src_dir = path.abspath(path.dirname(__file__)) completion = u"""\ #!/usr/bin/env bash _tqdm(){{ @@ -58,6 +56,5 @@ complete -F _tqdm tqdm """.format(opts=' '.join(sorted(options)), opts_manual='|'.join(sorted(options_input))) if __name__ == "__main__": - fncompletion = path.join(path.dirname(src_dir), 'tqdm', 'completion.sh') - with io_open(fncompletion, mode='w', encoding='utf-8') as fd: - fd.write(completion) + (Path(__file__).resolve().parent.parent / 'tqdm' / 'completion.sh').write_text( + completion, encoding='utf-8') diff --git a/tqdm/cli.py b/tqdm/cli.py index 44426283..1223d497 100644 --- a/tqdm/cli.py +++ b/tqdm/cli.py @@ -98,7 +98,7 @@ def posix_pipe(fin, fout, delim=b'\\n', buf_size=256, # ((opt, type), ... ) -RE_OPTS = re.compile(r'\n {8}(\S+)\s{2,}:\s*([^,]+)') +RE_OPTS = re.compile(r'\n {4}(\S+)\s{2,}:\s*([^,]+)') # better split method assuming no positional args RE_SHLEX = re.compile(r'\s*(?