sphinx-argparse-cli icon indicating copy to clipboard operation
sphinx-argparse-cli copied to clipboard

:prog: does not take effect for subcommands

Open lucc opened this issue 2 years ago • 3 comments

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

lucc avatar Dec 06 '22 08:12 lucc

I have also noticed this behavior on sphinx-argparse-cli==1.11.0 with sphinx==6.1.3

aldenmoreton avatar Mar 27 '23 14:03 aldenmoreton

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

MuellerSeb avatar Apr 06 '23 09:04 MuellerSeb

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 the sphinx_argparse_cli directive in man.rst
  • bug-example-3 is set in the constructor of the argparse.ArgumentParser

lucc avatar Apr 06 '23 16:04 lucc