diff --git a/shtab/__init__.py b/shtab/__init__.py index e29a2e9..683172f 100644 --- a/shtab/__init__.py +++ b/shtab/__init__.py @@ -245,9 +245,6 @@ def recurse(parser, prefix): options_strings_str = "' '".join(get_option_strings(parser)) option_strings.append(f"{prefix}_option_strings=('{options_strings_str}')") for optional in parser._get_optional_actions(): - if optional == SUPPRESS: - continue - for option_string in optional.option_strings: if hasattr(optional, "complete"): # shtab `.complete = ...` functions @@ -440,8 +437,7 @@ def complete_bash(parser, root_prefix=None, preamble="", choice_functions=None): if [[ $pos_only = 0 && "${completing_word}" == -* ]]; then # optional argument started: use option strings COMPREPLY=( $(compgen -W "${current_option_strings[*]}" -- "${completing_word}") ) - elif [[ "${previous_word}" == ">" || "${previous_word}" == ">>" || - "${previous_word}" =~ ^[12]">" || "${previous_word}" =~ ^[12]">>" ]]; then + elif [[ "${previous_word}" =~ ^[0-9\\&]*[\\<\\>]\\>?$ ]]; then # handle redirection operators COMPREPLY=( $(compgen -f -- "${completing_word}") ) else diff --git a/shtab/__main__.py b/shtab/__main__.py index 22c6f14..1018735 100644 --- a/shtab/__main__.py +++ b/shtab/__main__.py @@ -1,8 +1,7 @@ import logging -import sys from .main import main if __name__ == "__main__": logging.basicConfig(level=logging.INFO) - sys.exit(main(sys.argv[1:]) or 0) + main() diff --git a/tests/test_shtab.py b/tests/test_shtab.py index d730151..8e9161d 100644 --- a/tests/test_shtab.py +++ b/tests/test_shtab.py @@ -315,7 +315,7 @@ def test_add_argument_to_positional(shell, caplog, capsys): completion_manual = shtab.complete(parser, shell=shell) with pytest.raises(SystemExit) as exc: sub._actions[-1](sub, Namespace(), shell) - assert exc.type == SystemExit + assert exc.type is SystemExit assert exc.value.code == 0 completion, err = capsys.readouterr() print(completion)