Skip to content

Commit 34dfa38

Browse files
committed
bump version, merge branch 'devel'
2 parents 2a4b038 + 03824bd commit 34dfa38

File tree

2 files changed

+21
-4
lines changed

2 files changed

+21
-4
lines changed

shtab/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,7 @@ def recurse(parser, prefix):
204204
),
205205
file=fd,
206206
)
207-
else:
208-
assert isinstance(sub.choices, dict)
207+
elif isinstance(sub.choices, dict):
209208
log.debug("subcommand:%s", cmd)
210209
if sub.choices[cmd].add_help:
211210
commands.append(cmd)
@@ -215,6 +214,8 @@ def recurse(parser, prefix):
215214
)
216215
else:
217216
log.debug("skip:subcommand:%s", cmd)
217+
else:
218+
commands.append(cmd)
218219
else:
219220
log.debug("uncompletable:{}:{}".format(prefix, sub.dest))
220221

tests/test_shtab.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"""
77
import logging
88
import subprocess
9+
from argparse import ArgumentParser
910

1011
import pytest
1112

@@ -69,6 +70,14 @@ def test_choices():
6970
assert "" not in shtab.Required.FILE
7071

7172

73+
@pytest.mark.parametrize("shell", SUPPORTED_SHELLS)
74+
def test_main(shell, caplog):
75+
with caplog.at_level(logging.INFO):
76+
main(["-s", shell, "shtab.main.get_main_parser"])
77+
78+
assert not caplog.record_tuples
79+
80+
7281
@pytest.mark.parametrize("shell", SUPPORTED_SHELLS)
7382
def test_complete(shell, caplog):
7483
parser = get_main_parser()
@@ -84,8 +93,15 @@ def test_complete(shell, caplog):
8493

8594

8695
@pytest.mark.parametrize("shell", SUPPORTED_SHELLS)
87-
def test_main(shell, caplog):
96+
def test_positional_choices(shell, caplog):
97+
parser = ArgumentParser(prog="test")
98+
parser.add_argument("posA", choices=["one", "two"])
8899
with caplog.at_level(logging.INFO):
89-
main(["-s", shell, "shtab.main.get_main_parser"])
100+
completion = shtab.complete(parser, shell=shell)
101+
print(completion)
102+
103+
if shell == "bash":
104+
shell = Bash(completion)
105+
shell.compgen('-W "$_shtab_test_commands_"', "o", "one")
90106

91107
assert not caplog.record_tuples

0 commit comments

Comments
 (0)