Skip to content

Commit

Permalink
Merge pull request #10097 from tk0miya/10029_strip_value_from_cmdoption
Browse files Browse the repository at this point in the history
Fix #9981: std domain: Strip value part of the option directive from genindex
  • Loading branch information
tk0miya committed Jan 15, 2022
2 parents 542db8f + 008005c commit 3b8387f
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -43,6 +43,7 @@ Features added
* #10055: sphinx-build: Create directories when ``-w`` option given
* #9993: std domain: Allow to refer an inline target (ex. ``_`target name```)
via :rst:role:`ref` role
* #9981: std domain: Strip value part of the option directive from general index
* #9391: texinfo: improve variable in ``samp`` role
* #9578: texinfo: Add :confval:`texinfo_cross_references` to disable cross
references for readability with standalone readers
Expand Down
2 changes: 1 addition & 1 deletion sphinx/domains/std.py
Expand Up @@ -242,7 +242,7 @@ def add_target_and_index(self, firstname: str, sig: str, signode: desc_signature
descr = _('%s command line option') % currprogram
else:
descr = _('command line option')
for option in sig.split(', '):
for option in signode.get('allnames', []):
entry = '; '.join([descr, option])
self.indexnode['entries'].append(('pair', entry, signode['ids'][0], '', None))

Expand Down
9 changes: 5 additions & 4 deletions tests/test_domain_std.py
Expand Up @@ -97,6 +97,9 @@ def test_cmd_option_with_optional_value(app):
[desc, ([desc_signature, ([desc_name, '-j'],
[desc_addname, '[=N]'])],
[desc_content, ()])]))
assert_node(doctree[0], addnodes.index,
entries=[('pair', 'command line option; -j', 'cmdoption-j', '', None)])

objects = list(app.env.get_domain("std").get_objects())
assert ('-j', '-j', 'cmdoption', 'index', 'cmdoption-j', 1) in objects

Expand Down Expand Up @@ -355,10 +358,8 @@ def test_multiple_cmdoptions(app):
[desc_addname, " directory"])],
[desc_content, ()])]))
assert_node(doctree[0], addnodes.index,
entries=[('pair', 'cmd command line option; -o directory',
'cmdoption-cmd-o', '', None),
('pair', 'cmd command line option; --output directory',
'cmdoption-cmd-o', '', None)])
entries=[('pair', 'cmd command line option; -o', 'cmdoption-cmd-o', '', None),
('pair', 'cmd command line option; --output', 'cmdoption-cmd-o', '', None)])
assert ('cmd', '-o') in domain.progoptions
assert ('cmd', '--output') in domain.progoptions
assert domain.progoptions[('cmd', '-o')] == ('index', 'cmdoption-cmd-o')
Expand Down

0 comments on commit 3b8387f

Please sign in to comment.