hamdanal / rich-argparse

A rich help formatter for argparse
https://pypi.org/project/rich-argparse/
MIT License
129 stars 11 forks source link

Add a style for %(prog)s in the usage #56

Closed hamdanal closed 1 year ago

hamdanal commented 1 year ago

Closes #55

Add a new style for %(prog)s in the usage. The style is applied in argparse-generated usage and in user defined usage whether the user usage is plain text or rich markup.

Click to see the code ```python import argparse from rich import get_console from rich_argparse import RichHelpFormatter console = get_console() console.rule("Auto generated usage") parser = argparse.ArgumentParser( prog="connect", description="Edit or show the location of the user configuration file.", formatter_class=RichHelpFormatter, ) parser.print_usage() console.rule("User defined plain text usage") parser = argparse.ArgumentParser( prog="connect", description="Edit or show the location of the user configuration file.", usage="%(prog)s [-h] config_name\n %(prog)s [-h] url [user] [password]", formatter_class=RichHelpFormatter, ) parser.print_usage() console.rule("User defined markup usage") RichHelpFormatter.usage_markup = True parser = argparse.ArgumentParser( prog="connect", description="Edit or show the location of the user configuration file.", usage="[u]%(prog)s \\[-h] config_name[/]\n [i]%(prog)s \\[-h] url \\[user] \\[password][/]", formatter_class=RichHelpFormatter, ) parser.print_usage() ```

rich_argparse_prog_style