Skip to content

✨ feat: support the :option: role for CLI arguments - #346

Merged
gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:option-role
Aug 27, 2026
Merged

✨ feat: support the :option: role for CLI arguments#346
gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:option-role

Conversation

@gaborbernat

Copy link
Copy Markdown
Member

Linking to a rendered flag required the :ref: role with a hand-assembled anchor such as :ref:`tox-run---magic`, and a program or flag with a capital letter also needed :force_refs_lower:. Sphinx resolves the :option: role through its own progoptions table, keyed on program and option name, which the directive did not fill; #345 asks for this.

Each flag and positional argument now also registers with StandardDomain.add_program_option, using the same anchor id the :ref: labels already point at. :option:`tox run --magic` resolves, and so does a bare :option:`--magic` under a .. program:: tox run scope, including the --magic=value spelling Sphinx strips before lookup. 🔗

Existing URLs and :ref: targets stay as they were. Two limits remain. progoptions is keyed by program rather than document, so sphinx_argparse_cli_prefix_document does not apply and the first document rendering a program wins. Sphinx only strips =value when the program comes from .. program::, so :option:`tox --magic=1` stays unresolved. The README covers both.

Linking to a flag required the :ref: role with a hand-assembled anchor
(`tox-run---magic`), and mixed-case names also forced :force_refs_lower:
on. Sphinx resolves the :option: role through a separate `progoptions`
table keyed on program and option name, which the directive did not fill.

Each rendered flag and positional now also goes through
`StandardDomain.add_program_option`, under the same anchor id the :ref:
labels use, so `:option:`tox run --magic`` and a `.. program::` scope
both resolve without changing any existing URL.

Resolves tox-dev#345.
@gaborbernat gaborbernat added the enhancement New feature or request label Aug 27, 2026
@gaborbernat
gaborbernat merged commit f48653e into tox-dev:main Aug 27, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant