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

:prog: does not take effect for subcommands #71

Open
lucc opened this issue Dec 6, 2022 · 3 comments
Open

:prog: does not take effect for subcommands #71

lucc opened this issue Dec 6, 2022 · 3 comments
Assignees
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@lucc
Copy link

lucc commented Dec 6, 2022

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

@aldenmoreton
Copy link

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

@MuellerSeb
Copy link

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

lucc added a commit to lucc/sphinx-example that referenced this issue Apr 6, 2023
@lucc
Copy link
Author

lucc commented Apr 6, 2023

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

@gaborbernat gaborbernat added the help wanted Extra attention is needed label Sep 1, 2023
@gaborbernat gaborbernat added the bug Something isn't working label Sep 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants