This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mattlong
Recipients Brett.Hannigan, barry, bethard, derks, mattlong, paul.j3, r.david.murray
Date 2015-04-15.15:08:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1429110512.79.0.42611404613.issue22848@psf.upfronthosting.co.za>
In-reply-to
Content
I prefer the idea of help=SUPPRESSED resulting in a "hidden" subcommand. That is, one that does not show up at all in the usage/help output:

    import argparse

    parser = argparse.ArgumentParser(prog='myapp')
    parser.add_argument('--foo', action=CustomAction)
    sub_parsers = parser.add_subparsers(dest='commands', title='subcommands')
    sub_parser = sub_parsers.add_parser('sub-command-1', help='sub-command-1 help')
    sub_parser = sub_parsers.add_parser('sub-command-2', help=argparse.SUPPRESS)
    sub_parser = sub_parsers.add_parser('sub-command-3')

    parser.parse_args(['-h'])

Would result in:

usage: myapp [-h] [--foo FOO] {sub-command-1,sub-command-3} ...

optional arguments:
  -h, --help            show this help message and exit
  --foo FOO

subcommands:
  {sub-command-1,sub-command-3}
    sub-command-1       normal subcommand help


Assuming this behavior, what should happen if you request help for a subparser with help=SUPPRESSED? That is, you know the subcommand exists even though it's not mentioned in the usage. I would assume it would show usage as normal (note the description kwarg for sub-command-2):

    import argparse

    parser = argparse.ArgumentParser(prog='myapp')
    parser.add_argument('--foo', action='store_true')
    sub_parsers = parser.add_subparsers(dest='commands', title='subcommands')
    sub_parser = sub_parsers.add_parser('sub-command-1', help='sub-command-1 help')
    sub_parser = sub_parsers.add_parser('sub-command-2',
                                        help=argparse.SUPPRESS,
                                        description='description of suppressed sub-command-2')
    sub_parser = sub_parsers.add_parser('sub-command-3')

    parser.parse_args(['sub-command-2', '-h'])

Would result in:

usage: myapp sub-command-2 [-h]

description of suppressed sub-command-2

optional arguments:
  -h, --help  show this help message and exit


An edge case to consider: what should top-level help look like if ALL subparsers are suppressed? It seems like a degenerate scenario, but complete is important, right? The one that feels most correct to me is to follow the current behavior when you call add_subparsers but never call add_parser:

    import argparse

    parser = argparse.ArgumentParser(prog='myapp')
    parser.add_argument('--foo', action='store_true')
    sub_parsers = parser.add_subparsers(dest='commands', title='subcommands')
    parser.parse_args(['-h'])

Currently results in:
usage: myapp [-h] [--foo] {} ...

optional arguments:
  -h, --help  show this help message and exit
  --foo

subcommands:
  {}

Another possibility would be to follow the current behavior when you never even call add_subparsers which would of course remove all notion that subcommands are accepted, but that doesn't feel right to me.
History
Date User Action Args
2015-04-15 15:08:32mattlongsetrecipients: + mattlong, barry, bethard, r.david.murray, derks, paul.j3, Brett.Hannigan
2015-04-15 15:08:32mattlongsetmessageid: <1429110512.79.0.42611404613.issue22848@psf.upfronthosting.co.za>
2015-04-15 15:08:32mattlonglinkissue22848 messages
2015-04-15 15:08:32mattlongcreate