mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2026-09-03 20:52:55 -05:00
Closes #1357: Option names documented by :rst:dir:option are now again allowed to
not start with a dash or slash, and referencing them will work correctly.
This commit is contained in:
@@ -8,6 +8,8 @@ Bugs fixed
|
||||
the full relative path and not the basename.
|
||||
* PR#212: Fix traceback with autodoc and ``__init__`` methods without docstring.
|
||||
* PR#213: Fix a missing import in the setup command.
|
||||
* #1357: Option names documented by :rst:dir:`option` are now again allowed to
|
||||
not start with a dash or slash, and referencing them will work correctly.
|
||||
|
||||
Documentation
|
||||
-------------
|
||||
|
||||
+9
-5
@@ -632,16 +632,20 @@ There is a set of directives allowing documenting command-line programs:
|
||||
|
||||
.. rst:directive:: .. option:: name args, name args, ...
|
||||
|
||||
Describes a command line option or switch. Option argument names should be
|
||||
enclosed in angle brackets. Example::
|
||||
Describes a command line argument or switch. Option argument names should be
|
||||
enclosed in angle brackets. Examples::
|
||||
|
||||
.. option:: dest_dir
|
||||
|
||||
Destination directory.
|
||||
|
||||
.. option:: -m <module>, --module <module>
|
||||
|
||||
Run a module as a script.
|
||||
|
||||
The directive will create a cross-reference target named after the *first*
|
||||
option, referencable by :rst:role:`option` (in the example case, you'd use
|
||||
something like ``:option:`-m```).
|
||||
The directive will create cross-reference targets for the given options,
|
||||
referencable by :rst:role:`option` (in the example case, you'd use something
|
||||
like ``:option:`dest_dir```, ``:option:`-m```, or ``:option:`--module```).
|
||||
|
||||
.. rst:directive:: .. envvar:: name
|
||||
|
||||
|
||||
+23
-15
@@ -27,7 +27,7 @@ from sphinx.util.compat import Directive
|
||||
|
||||
|
||||
# RE for option descriptions
|
||||
option_desc_re = re.compile(r'((?:/|-|--)[-_a-zA-Z0-9]+)(\s*.*)')
|
||||
option_desc_re = re.compile(r'((?:/|-|--)?[-_a-zA-Z0-9]+)(\s*.*)')
|
||||
|
||||
|
||||
class GenericObject(ObjectDescription):
|
||||
@@ -143,7 +143,7 @@ class Cmdoption(ObjectDescription):
|
||||
self.env.warn(
|
||||
self.env.docname,
|
||||
'Malformed option description %r, should '
|
||||
'look like "-opt args", "--opt args" or '
|
||||
'look like "opt", "-opt args", "--opt args" or '
|
||||
'"/opt args"' % potential_option, self.lineno)
|
||||
continue
|
||||
optname, args = m.groups()
|
||||
@@ -153,25 +153,33 @@ class Cmdoption(ObjectDescription):
|
||||
signode += addnodes.desc_addname(args, args)
|
||||
if not count:
|
||||
firstname = optname
|
||||
signode['allnames'] = [optname]
|
||||
else:
|
||||
signode['allnames'].append(optname)
|
||||
count += 1
|
||||
if not firstname:
|
||||
raise ValueError
|
||||
return firstname
|
||||
|
||||
def add_target_and_index(self, name, sig, signode):
|
||||
targetname = name.replace('/', '-')
|
||||
def add_target_and_index(self, firstname, sig, signode):
|
||||
currprogram = self.env.temp_data.get('std:program')
|
||||
if currprogram:
|
||||
targetname = '-' + currprogram + targetname
|
||||
targetname = 'cmdoption' + targetname
|
||||
signode['ids'].append(targetname)
|
||||
self.state.document.note_explicit_target(signode)
|
||||
self.indexnode['entries'].append(
|
||||
('pair', _('%scommand line option; %s') %
|
||||
((currprogram and currprogram + ' ' or ''), sig),
|
||||
targetname, ''))
|
||||
self.env.domaindata['std']['progoptions'][currprogram, name] = \
|
||||
self.env.docname, targetname
|
||||
for optname in signode.get('allnames', []):
|
||||
targetname = optname.replace('/', '-')
|
||||
if not targetname.startswith('-'):
|
||||
targetname = '-arg-' + targetname
|
||||
if currprogram:
|
||||
targetname = '-' + currprogram + targetname
|
||||
targetname = 'cmdoption' + targetname
|
||||
signode['ids'].append(targetname)
|
||||
self.state.document.note_explicit_target(signode)
|
||||
self.env.domaindata['std']['progoptions'][currprogram, optname] = \
|
||||
self.env.docname, targetname
|
||||
# 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),
|
||||
targetname, ''))
|
||||
|
||||
|
||||
class Program(Directive):
|
||||
|
||||
Reference in New Issue
Block a user