Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross Referencing Program Objects #880

Open
shimizukawa opened this issue Jan 3, 2015 · 8 comments
Open

Cross Referencing Program Objects #880

shimizukawa opened this issue Jan 3, 2015 · 8 comments
Labels
domains:std markup type:enhancement enhance or introduce a new feature

Comments

@shimizukawa
Copy link
Member

I'm using Sphinx to document a software product that includes a number
of command line utilities. I've documented the utilities themselves
using the standard domain's "program" and "option" directive, but I
find myself often talking about these programs in the text of the
documentation itself, and I would like to be able to cross reference
the "manual page," when I mention the program's name.

The easiest/best way would be if the :program: role would link to the
page that has "program" directive.

In an attempt to find a work around for this I've encountered another
issue:

I attempted create a new "binary" role and directive combination in a
custom domain, inserted these "binary" directives with the name of the
utility on the same manual page that has a program directive and
discovered that cross-referencing would not work for these links, even
though the "binary" and the "program" directives exist in different
domains. At the same time cross-references work if when "binary"
directive holds a term that isn't duplicated by the value of a program
directive.

Is there a work around for this collision, or a recommended way of
referencing these kinds of objects.


@shimizukawa shimizukawa added type:enhancement enhance or introduce a new feature other labels Jan 3, 2015
@kvalev
Copy link
Contributor

kvalev commented Oct 16, 2017

It seems that cross-referencing an program directive is not possible, right?

@kratsg
Copy link

kratsg commented Dec 12, 2019

FYI, it seems to be possible just by doing

Test, abc |cli foo|_

.. |cli foo| replace:: ``cli foo``

but I can't find documentation on this...

@ulijh
Copy link

ulijh commented Jun 8, 2020

I can't get this to work. At least not with commands containing dashes.

@tk0miya tk0miya added this to the 3.2.0 milestone Jun 8, 2020
@tk0miya tk0miya modified the milestones: 3.2.0, 3.3.0 Jul 19, 2020
@tk0miya tk0miya modified the milestones: 3.3.0, 3.4.0 Oct 4, 2020
@tk0miya tk0miya modified the milestones: 3.4.0, 3.5.0 Dec 19, 2020
@tk0miya
Copy link
Member

tk0miya commented Dec 29, 2020

The current implementation of program directive behaves like a context switcher. It's similar to currentmodule directive. To realize the cross-reference feature, we need to generate an anchor to the definition. But I worried it causes conflicts. It might be better to add a new directive for such purpose. But I don't have a good naming ideas...

@tk0miya tk0miya modified the milestones: 3.5.0, 4.0.0 Feb 4, 2021
@tk0miya tk0miya modified the milestones: 4.0.0, 4.1.0 Mar 8, 2021
@tk0miya tk0miya modified the milestones: 4.1.0, 5.0.0 Jul 10, 2021
@waveform80
Copy link

The current implementation of program directive behaves like a context switcher. It's similar to currentmodule directive. To realize the cross-reference feature, we need to generate an anchor to the definition. But I worried it causes conflicts. It might be better to add a new directive for such purpose. But I don't have a good naming ideas...

Given the option directive already generates anchors (taking part of their identifier from the preceding program directive), could the program directive not similarly generate an anchor. In other words, make it akin to the module directive, as opposed to the currentmodule directive?

I'm probably missing something, but looking at the markup generated in our pinout -h documentation and the anchor being "cmdoption-pinout-h" which is obviously composed of the .. program:: pinout and .. option:: -h directives declaring it, I would assume that an anchor like "cmdoption-pinout" (with no option portion) or "cmd-pinout" (if a different prefix were preferable) would be reasonably unique?

@jakobandersen
Copy link
Contributor

You may have multiple places in a document where you use .. program:: so it is not clear which should generate the anchor. Similarly the py:currentmodule directive can be used multiple time.
But perhaps we could figure out a good name for a new directive which defines the anchor and shows the options for the program, or similar.

@waveform80
Copy link

You may have multiple places in a document where you use .. program:: so it is not clear which should generate the anchor. Similarly the py:currentmodule directive can be used multiple time. But perhaps we could figure out a good name for a new directive which defines the anchor and shows the options for the program, or similar.

Re-reading the docs for the program directive you're clearly correct, and I've obviously been under the mistaken impression that the program directive was like the module directive (i.e. that it's used in a single place in the docs to define "this is the start of the documentation for program/module X").

That said, I'm struggling to imagine where/why one might wish to split up the options for a program in a set of documentation (again, I may be missing something obvious). Realizing that I'm proposing something that would potentially break backwards compatibility, might it be preferable to re-define the program directive along the lines of the module directive, and introduce a currentprogram directive (akin to the currentmodule directive)?

Alternatively, rather than breaking compatibility (and in keeping with the OP), perhaps introduce a binary directive and a corresponding currentbinary directive (the latter effectively being an alias of the existing program directive, which could potentially be deprecated in favour of currentbinary at some future point)?

Come to think of it, I'm not entirely sold on "binary" -- it's a bit too all-encompassing. Perhaps "executable" or "application" (or possibly "script", though that comes with its own implications) to make it clear that the binary in question is something intended to be run by the user?

@tk0miya tk0miya modified the milestones: 5.0.0, 5.x May 2, 2022
@AA-Turner AA-Turner removed this from the 5.x milestone May 23, 2022
@s-m-e
Copy link

s-m-e commented May 23, 2023

Just ran into this. Idea for a potential workaround that would not break backwards compatibility (?):

Imaging having a page explaining your tool, cli.html via cli.rst, one with sub commands like git:

.. _cli:

CLI
===

The command line usage of `git` ...

.. click:: git.cli:cli
  :prog: git
  :nested: full

If I want to reference e.g. git commit, the best bad thing I could do at the moment is:

:ref:`git commit <cli>`

This brings me to the top of the CLI page. However, looking at the output of sphinx, it has already generated an anchor: cli.html#git-commit. Why not expose this as a reference, by allowing something along the lines of:

:ref:`git commit <click-git-commit>`

Maybe this is a less invasive change?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domains:std markup type:enhancement enhance or introduce a new feature
Projects
None yet
Development

No branches or pull requests

9 participants