8000 Questions re: bracket and brace rendering · Issue #59 · hamdanal/rich-argparse · GitHub
[go: up one dir, main page]

Skip to content
Questions re: bracket and brace rendering #59
@kotfu

Description

@kotfu

Consider the following argument parser:

import argparse
import rich.console
from rich_argparse import RichHelpFormatter

console = rich.console.Console(markup=False, emoji=False, highlight=False)
parser = argparse.ArgumentParser(
    prog="list",
    description="Show all installed applications",
    add_help=False,
    formatter_class=RichHelpFormatter,
)
parser.add_argument(
    "config_name",
    nargs="?",
    help="a configuration name",
)
parser.add_argument(
    "-r",
    "--raw",
    action="store_true",
    required=True,
    help="show apps without formatting",
)
mutex = parser.add_mutually_exclusive_group()
mutex.add_argument(
    "--rich",
    action="store_true",
    help="Rich and poor are mutually exclusive. Choose either one but not both.",
)
mutex.add_argument(
    "--poor", action="store_false", dest="rich", help="Does poor mean --not-rich 😉?"
)
parser.add_argument(
    "-s",
    "--state",
    choices=["running", "stopped"],
    help="only show apps in a given state",
)
console.print(parser.format_help())

Note the inconsistent highlighting of brackets and braces.

  • options (i.e. -s) that are not required are surrounded in unstyled brackets
  • positional arguments that are not required (i.e. config_name) are surrounded by brackets styled with argparse.args
  • the mutually exclusive options --rich and --poor are surrounded by unstyled brackets and separated by an unstyled pipe character
  • the choices for the -s option are also mutually exclusive. They are surrounded by braces, and separated by a comma, but the braces and comma are styled with argparse.metavar

Observation: The brackets around optional arguments and the pipe separating the mutually exclusive options are the only text output which can not be styled using RichHelpFormatter.styles.

Suggestion: choices for an option (i.e. -s) of which you can only choose one, and mutually exclusive options (i.e. --rich and --poor), of which you can only choose one, should be rendered consistently.

Questions:

  • Are these behaviors with [brackets|braces|commas|pipes] intentional?
  • If not, would you consider rendering all of these symbols (braces, brackets, commas, pipes) with a new style, perhaps something like "argparse.symbols"?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0