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

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

Merged
merged 2 commits into from
Feb 25, 2023
Merged

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

merged 2 commits into from
Feb 25, 2023

Conversation

hamdanal
Copy link
Owner

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
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

@hamdanal hamdanal added the enhancement New feature or request label Feb 25, 2023
@hamdanal hamdanal merged commit 2ffac91 into main Feb 25, 2023
@hamdanal hamdanal deleted the prog-style branch February 25, 2023 19:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement argparse.prog style
1 participant