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

Missing hyphens #115

Open
madebr opened this issue Sep 2, 2019 · 3 comments
Open

Missing hyphens #115

madebr opened this issue Sep 2, 2019 · 3 comments

Comments

@madebr
Copy link

madebr commented Sep 2, 2019

Hello,
when creating a man page out of an ArgumentParser, the starting hyphen is not rendered.
So the option --yes is shown as -yes in the man page.
Similarly, a -y is shown as y.

I can reproduce the issue with the following code:

cd /tmp
rm -rf WORKDIR
mkdir WORKDIR
cd WORKDIR

sphinx-quickstart $PWD --extensions sphinxarg.ext --sep -p option_bug -a author -r 0.1 -l en --no-batchfile --makefile

cat >>source/conf.py <<EOF

man_pages = [
    ('cmd_main', 'tmpmain', 'tmpmain Documentation',
     ['name of author'], 1)
]

import sys
import os
sys.path.insert(0, os.path.dirname(os.getcwd()))

EOF

mkdir pymodule
touch pymodule/__init__.py
cat >pymodule/tmpmain.py <<EOF
#!/usr/bin/env python3
import argparse
def my_func_that_returns_a_parser():
    parser = argparse.ArgumentParser()
    parser.add_argument('foo', default=False, help='foo help')
    parser.add_argument('bar', default=False)
    parser.add_argument('--general', '-G', default=False, help='General option')

    subparsers = parser.add_subparsers()

    subparser = subparsers.add_parser('install', help='install help')
    subparser.add_argument('ref', type=str, help='foo1 help')
    subparser.add_argument('--upgrade', action='store_true', default=False, help='foo2 help')
    subparser.add_argument('-U', action='store_true', default=False, help='foo3 help')

    return parser
if __name__ == '__main__':
    p = my_func_that_returns_a_parser()
    p.parse_args()
EOF
chmod a+x pymodule/tmpmain.py

cat >source/index.rst <<EOF

Welcome to pymodule's documentation!
====================================

.. toctree::
   :maxdepth: 2
   :caption: Contents:

   cmd_main
EOF

cat >source/cmd_main.rst <<EOF
.. argparse::
   :module: pymodule.tmpmain
   :func: my_func_that_returns_a_parser
   :prog: fancytool
EOF

make man

man build/man/tmpmain.1
@lucc
Copy link

lucc commented Feb 20, 2021

This also happens to me.

It appears that in the generated man page the lines start with

.B\-\-foo

If I manually edit this to add a space after the B and before the first \- it looks good when viewed with man:

.B \-\-foo

@JOJ0
Copy link

JOJ0 commented Feb 21, 2021

yep, same here, first hyphen of --option gets lost as well as single hyphen of short form option. leaving manpage rendering unusable. Pretty frustrating as sphinx-argparse appeared to be a promising module for my needs. Found any workaround @lucc except manually editing the generated manpage file? Any other usable results with other tools? I am playing around with sphinxcontrib-autoprogram at the moment - this works a little better but does not have as much additional editing options as sphinx-argparse (like adding additional restructured text before or after certain sections in the generated manpages/html pages.)

sorry, maybe this is not the right place to share experience with manpage autogeneration tools but as it's frustrating enough already I don't see another option :-)

and I really do hope that taking over maintenance of this repo as discussed in #135 works out in the end and bugs like this get fixed. Is there a PR open for a fix yet?

@lucc
Copy link

lucc commented Feb 21, 2021

I had a look at the code yesterday but noticed that I don't have any idea how sphinx works and how a plugin can integrate with that (it is by no means a small script which you read through and understand the gist of it at a glance 😄 ).

I found this line: https://github.com/alex-rudakov/sphinx-argparse/blob/master/sphinxarg/ext.py#L152 but I did not look into running sphinx with a local checkout of this extension. Maybe we just have to add a space in from of term in case it is non empty. I was to lazy to dig into sphinx internals to test this hypothesis.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants