From a29de95e9467b94130b52ce9644a813535f71b4d Mon Sep 17 00:00:00 2001 From: Wu Zhenyu Date: Sat, 29 Oct 2022 16:15:54 +0800 Subject: [PATCH 1/4] Fix #89 --- shtab/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shtab/main.py b/shtab/main.py index 36cd68c..4e4c9d9 100644 --- a/shtab/main.py +++ b/shtab/main.py @@ -4,13 +4,14 @@ import sys from importlib import import_module -from . import SUPPORTED_SHELLS, __version__, complete +from . import SUPPORTED_SHELLS, __version__, add_argument_to, complete log = logging.getLogger(__name__) def get_main_parser(): parser = argparse.ArgumentParser(prog="shtab") + add_argument_to(parser) parser.add_argument("parser", help="importable parser (or function returning parser)") parser.add_argument("--version", action="version", version="%(prog)s " + __version__) parser.add_argument("-s", "--shell", default=SUPPORTED_SHELLS[0], choices=SUPPORTED_SHELLS) From 7208c429101dcf6373e857a60c42648a25725925 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Thu, 30 Mar 2023 19:14:32 +0100 Subject: [PATCH 2/4] minor tidy & inline comment --- shtab/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shtab/main.py b/shtab/main.py index 4e4c9d9..37d7d23 100644 --- a/shtab/main.py +++ b/shtab/main.py @@ -11,7 +11,6 @@ def get_main_parser(): parser = argparse.ArgumentParser(prog="shtab") - add_argument_to(parser) parser.add_argument("parser", help="importable parser (or function returning parser)") parser.add_argument("--version", action="version", version="%(prog)s " + __version__) parser.add_argument("-s", "--shell", default=SUPPORTED_SHELLS[0], choices=SUPPORTED_SHELLS) @@ -27,6 +26,7 @@ def get_main_parser(): ) parser.add_argument("--verbose", dest="loglevel", action="store_const", default=logging.INFO, const=logging.DEBUG, help="Log debug information") + add_argument_to(parser) # add `--print-completion` option (dogfooding) return parser From 0cbeccfca3217a934315af6546435cfa8db87ef9 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Thu, 30 Mar 2023 19:31:28 +0100 Subject: [PATCH 3/4] tests: shtab --print-completion --- tests/test_shtab.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/test_shtab.py b/tests/test_shtab.py index f0f1f11..f4616ac 100644 --- a/tests/test_shtab.py +++ b/tests/test_shtab.py @@ -64,6 +64,24 @@ def test_main(shell, caplog): assert not caplog.record_tuples +@fix_shell +def test_main_self_completion(shell, caplog, capsys): + with caplog.at_level(logging.INFO): + try: + main(["--print-completion", shell]) + except SystemExit: + pass + + captured = capsys.readouterr() + assert not captured.err + expected = { + "bash": "complete -o filenames -F _shtab_shtab shtab", "zsh": "_shtab_shtab_commands()", + "tcsh": "complete shtab"} + assert expected[shell] in captured.out + + assert not caplog.record_tuples + + @fix_shell def test_prog_override(shell, caplog, capsys): with caplog.at_level(logging.INFO): From 40413bb9d81634ec63ec103f3c53d18e54561c48 Mon Sep 17 00:00:00 2001 From: Casper da Costa-Luis Date: Thu, 30 Mar 2023 19:35:56 +0100 Subject: [PATCH 4/4] reduce chance of dogfooding confusion --- shtab/main.py | 2 +- tests/test_shtab.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/shtab/main.py b/shtab/main.py index 37d7d23..bec291d 100644 --- a/shtab/main.py +++ b/shtab/main.py @@ -26,7 +26,7 @@ def get_main_parser(): ) parser.add_argument("--verbose", dest="loglevel", action="store_const", default=logging.INFO, const=logging.DEBUG, help="Log debug information") - add_argument_to(parser) # add `--print-completion` option (dogfooding) + add_argument_to(parser, "--print-own-completion", help="print shtab's own completion") return parser diff --git a/tests/test_shtab.py b/tests/test_shtab.py index f4616ac..e07cede 100644 --- a/tests/test_shtab.py +++ b/tests/test_shtab.py @@ -68,7 +68,7 @@ def test_main(shell, caplog): def test_main_self_completion(shell, caplog, capsys): with caplog.at_level(logging.INFO): try: - main(["--print-completion", shell]) + main(["--print-own-completion", shell]) except SystemExit: pass