From 99d9a6f12388742fc07c455ed8ad473f9f666edd Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 16 Jun 2019 18:58:34 +0900 Subject: [PATCH] Close #5592: option directive registers an index entry for each comma separated option --- CHANGES | 2 ++ sphinx/domains/std.py | 14 ++++++++------ tests/test_domain_std.py | 26 ++++++++++++++------------ 3 files changed, 24 insertions(+), 18 deletions(-) diff --git a/CHANGES b/CHANGES index 6e38020e8..c4f4c3c52 100644 --- a/CHANGES +++ b/CHANGES @@ -30,6 +30,8 @@ Bugs fixed ---------- * py domain: duplicated warning does not point the location of source code +* #5592: std domain: :rst:dir:`option` directive registers an index entry for + each comma separated option * #1125: html theme: scrollbar is hard to see on classic theme and macOS * #5502: linkcheck: Consider HTTP 503 response as not an error * #6439: Make generated download links reproducible diff --git a/sphinx/domains/std.py b/sphinx/domains/std.py index 01cc797c3..5c35083fd 100644 --- a/sphinx/domains/std.py +++ b/sphinx/domains/std.py @@ -202,12 +202,14 @@ class Cmdoption(ObjectDescription): domain.add_program_option(currprogram, optname, self.env.docname, signode['ids'][0]) - # create only one index entry for the whole option - if optname == firstname: - self.indexnode['entries'].append( - ('pair', _('%scommand line option; %s') % - ((currprogram and currprogram + ' ' or ''), sig), - signode['ids'][0], '', None)) + # create an index entry + if currprogram: + descr = _('%s command line option') % currprogram + else: + descr = _('command line option') + for option in sig.split(', '): + entry = '; '.join([descr, option]) + self.indexnode['entries'].append(('pair', entry, signode['ids'][0], '', None)) class Program(SphinxDirective): diff --git a/tests/test_domain_std.py b/tests/test_domain_std.py index b4528a6c9..1a03060e6 100644 --- a/tests/test_domain_std.py +++ b/tests/test_domain_std.py @@ -261,22 +261,24 @@ def test_cmdoption(app): def test_multiple_cmdoptions(app): - text = (".. program:: ls\n" + text = (".. program:: cmd\n" "\n" - ".. option:: -h, --help\n") + ".. option:: -o directory, --output directory\n") domain = app.env.get_domain('std') doctree = restructuredtext.parse(app, text) assert_node(doctree, (addnodes.index, - [desc, ([desc_signature, ([desc_name, "-h"], - [desc_addname, ()], + [desc, ([desc_signature, ([desc_name, "-o"], + [desc_addname, " directory"], [desc_addname, ", "], - [desc_name, "--help"], - [desc_addname, ()])], + [desc_name, "--output"], + [desc_addname, " directory"])], [desc_content, ()])])) assert_node(doctree[0], addnodes.index, - entries=[('pair', 'ls command line option; -h, --help', - 'cmdoption-ls-h', '', None)]) - assert ('ls', '-h') in domain.progoptions - assert ('ls', '--help') in domain.progoptions - assert domain.progoptions[('ls', '-h')] == ('index', 'cmdoption-ls-h') - assert domain.progoptions[('ls', '--help')] == ('index', 'cmdoption-ls-h') + entries=[('pair', 'cmd command line option; -o directory', + 'cmdoption-cmd-o', '', None), + ('pair', 'cmd command line option; --output directory', + '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') + assert domain.progoptions[('cmd', '--output')] == ('index', 'cmdoption-cmd-o')