Skip to content

Commit a97c7e5

Browse files
committed
Fix navigate bug with aliased subcommands
* Fixes #108 * Add an `identifier` field to data for aliased subcommands containing only the non-aliased name of the subcommand. * Modify `parser_navigate` to use this `identifier` when it is present.
1 parent d61cb05 commit a97c7e5

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

sphinxarg/parser.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ def parser_navigate(parser_result, path, current_path=None):
2020
' '.join(current_path))
2121
next_hop = path.pop(0)
2222
for child in parser_result['children']:
23-
if child['name'] == next_hop:
23+
# identifer is only used for aliased subcommands
24+
identifier = child['identifier'] if 'identifier' in child else child['name']
25+
if identifier == next_hop:
2426
current_path.append(next_hop)
2527
return parser_navigate(child, path, current_path)
2628
raise NavigationException(
@@ -88,6 +90,8 @@ def parse_parser(parser, data=None, **kwargs):
8890
'usage': subaction.format_usage().strip(),
8991
'bare_usage': _format_usage_without_prefix(subaction),
9092
}
93+
if subalias:
94+
subdata['identifier'] = name
9195
parse_parser(subaction, subdata, **kwargs)
9296
data.setdefault('children', []).append(subdata)
9397

test/test_parser.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ def test_parse_nested_with_alias():
214214
assert data['children'] == [
215215
{
216216
'name': 'install (i)',
217+
'identifier': 'install',
217218
'help': 'install help',
218219
'usage': 'usage: py.test install [-h] [--upgrade] ref',
219220
'bare_usage': 'py.test install [-h] [--upgrade] ref',
@@ -258,7 +259,8 @@ def test_aliased_traversal():
258259
'bare_usage': 'py.test level1 [-h]',
259260
'help': '',
260261
'usage': 'usage: py.test level1 [-h]',
261-
'name': 'level1'})
262+
'name': 'level1 (l1)',
263+
'identifier': 'level1'})
262264

263265
def test_parse_nested_traversal():
264266
parser = argparse.ArgumentParser()

0 commit comments

Comments
 (0)