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

doc: add ability to disambiguate clicmds #14509

Merged
merged 2 commits into from
Jun 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 49 additions & 6 deletions doc/user/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import pygments
import sphinx
from sphinx.highlighting import lexers
from sphinx.domains.std import GenericObject
from docutils.parsers.rst import directives

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
Expand Down Expand Up @@ -373,13 +375,54 @@ def vparse(s):
return a[:3]


# custom extensions here
class ClicmdDirective(GenericObject):
"""
Directive for documenting CLI commands.

The xref string, if no option is provided, will be the verbatim command
string. If the :daemon: option is provided, then it's
"(<daemon>) <command string>)".

Options:
:daemon: - specify the daemon this command belongs to. Useful for
disambiguating multiple definitions of the same command.
"""

has_content = True
required_arguments = 1
optional_arguments = 0
option_spec = {
**GenericObject.option_spec,
"daemon": directives.unchanged,
}

def handle_signature(self, sig, signode):
name = super().handle_signature(sig, signode)
daemon = self.options["daemon"] if "daemon" in self.options else ""
prefix = f"({daemon}) " if daemon else ""
return prefix + name

def run(self):
daemon = self.options["daemon"] if "daemon" in self.options else ""
if daemon:
self.indextemplate = f"pair: ({daemon}) %s; configuration command"
else:
self.indextemplate = f"pair: %s; configuration command"

nodes = super().run()

return nodes


def setup(app):
# object type for FRR CLI commands, can be extended to document parent CLI
# node later on
app.add_object_type(
"clicmd", "clicmd", indextemplate="pair: %s; configuration command"
)
# Override the directive that was just created for us
if int(sphinx.__version__.split(".")[0]) >= 2:
app.add_object_type("clicmd", "clicmd", objname="CLI command")
app.add_directive_to_domain("std", "clicmd", ClicmdDirective, override=True)
else:
app.add_object_type(
"clicmd", "clicmd", indextemplate="pair: %s; configuration command"
)

# I dont care how stupid this is
if "add_js_file" in dir(app):
Expand Down
Loading