praiskup / argparse-manpage

Automatically build man-pages for your Python project
Apache License 2.0
40 stars 22 forks source link

The generated manpage shows hidden commands. #51

Closed Artanias closed 2 years ago

Artanias commented 2 years ago

Hi, I have a question.

I have example:

import argparse

def get_parser():
    parser = argparse.ArgumentParser(prog='bestcli')
    level1 = parser.add_subparsers(help="First level.", metavar='{}')
    first_hidden_cmd = level1.add_parser('first_hidden_cmd')

    level2 = first_hidden_cmd.add_subparsers(help="Second level.", metavar='{}')
    second_hidden_cmd = level2.add_parser('second_hidden_cmd')
    third_hidden_cmd = level2.add_parser('third_hidden_cmd')

    second_hidden_cmd.add_argument('--bar', help='Show bar', action='store_false')
    third_hidden_cmd.add_argument('--xar', help='Show xar', action='store_true')

    fourth_hidden_cmd = level1.add_parser('fourth_hidden_cmd')
    fourth_hidden_cmd.add_argument('--foo', help='Show foo', action='store_true')

    return parser

And output is:

bestcli(1)                                                General Commands Manual                                               bestcli(1)

NAME
       bestcli

SYNOPSIS
       bestcli [-h] {} ...

POSITIONAL ARGUMENTS
COMMAND 'bestcli first_hidden_cmd'
       usage: bestcli first_hidden_cmd [-h] {} ...

POSITIONAL ARGUMENTS 'bestcli first_hidden_cmd'
COMMAND 'bestcli first_hidden_cmd second_hidden_cmd'
       usage: bestcli first_hidden_cmd second_hidden_cmd [-h] [--bar]

OPTIONS 'bestcli first_hidden_cmd second_hidden_cmd'
       --bar  Show bar

COMMAND 'bestcli first_hidden_cmd third_hidden_cmd'
       usage: bestcli first_hidden_cmd third_hidden_cmd [-h] [--xar]

OPTIONS 'bestcli first_hidden_cmd third_hidden_cmd'
       --xar  Show xar

COMMAND 'bestcli fourth_hidden_cmd'
       usage: bestcli fourth_hidden_cmd [-h] [--foo]

OPTIONS 'bestcli fourth_hidden_cmd'
       --foo  Show foo

Is this expected behavior or the commands should also be hidden in the manpage, as if we had called $ bestcli -h?

$ python3 bestcli.py -h
usage: bestcli [-h] {} ...

positional arguments:
  {}          First level.

optional arguments:
  -h, --help  show this help message and exit
praiskup commented 2 years ago

Sorry I missed your question. This is expected behavior -- we are able to generate only one manual page for one argument parser at this moment (so the goal is to have as complete manual page as possible). There wasn't a demand for a different behavior so far; so patches are welcome!

praiskup commented 2 years ago

so patches are welcome!

I will close this issue by repeating the above ^^ :-) looking forward for the patches, or at least formal RFEs.