sphinx-argparse-cli
sphinx-argparse-cli copied to clipboard
:prog: does not take effect for subcommands
I am using the :prog:
keyword for the sphinx_argparse_cli
directive but it appears that it only affects the first display of the command name. The main command name for the subcommands is shown as sphinx-build
.
My rst directive
.. sphinx_argparse_cli::
:module: example.cli
:func: parser
:prog: bug-example
:title: Synopsis
My build command: make man
The result with MANWIDTH=80 PAGER=cat man _build/man/prog.1
:
PROG(1) bug-example PROG(1)
NAME
prog - bug example
SYNOPSIS
bug-example [-h] {foo} ...
bug-example options
• -h, --help - show this help message and exit
sphinx-build foo
sphinx-build foo [-h]
sphinx-build foo options
• -h, --help - show this help message and exit
COPYRIGHT
2022, me
Dec 06, 2022 PROG(1)
The full example repository to reproduce this: https://github.com/lucc/sphinx-example
I have also noticed this behavior on sphinx-argparse-cli==1.11.0 with sphinx==6.1.3
As a workaround, you can explicitly set the program name in the parent parser with the prog
argument:
parser = argparse.ArgumentParser(prog='myprogram')
https://docs.python.org/3/library/argparse.html#prog
Thanks @MuellerSeb that looks promising. I tried it in lucc/sphinx-example@c68d3bc and the rendered man page looks like this:
BUG-EXAMPLE-1(1) bug-example BUG-EXAMPLE-1(1)
NAME
bug-example-1 - bug example
SYNOPSIS
bug-example-2 [-h] {foo} ...
bug-example-2 options
• -h, --help - show this help message and exit
bug-example-3 foo
bug-example-3 foo [-h]
bug-example-3 foo options
• -h, --help - show this help message and exit
COPYRIGHT
2022, me
Apr 06, 2023 BUG-EXAMPLE-1(1)
- bug-example-1 is set in conf.py as the name of the man page (it is also the file name of the man page)
- bug-example-2 is set in the
:prog:
keyword for thesphinx_argparse_cli
directive in man.rst - bug-example-3 is set in the constructor of the
argparse.ArgumentParser