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

Does a rich_argparse example fit in the documentation anywhere? #2

Closed
peterjc opened this issue Nov 5, 2024 · 3 comments
Closed

Does a rich_argparse example fit in the documentation anywhere? #2

peterjc opened this issue Nov 5, 2024 · 3 comments

Comments

@peterjc
Copy link

peterjc commented Nov 5, 2024

I was pleased to find I could combine yapx with rich_argparse (from https://github.com/hamdanal/rich-argparse ) as follows:

from rich_argparse import RichHelpFormatter
import yapx

def say_hello(name: str = 'World'):
    print(f"Hello {name}")

yapx.run(say_hello, formatter_class=RichHelpFormatter)

Sample output with the colours done via rich (cropped):

Screenshot 2024-11-05 at 19 29 50

Can you see where this might fit in the yapx documentation?

@peterjc
Copy link
Author

peterjc commented Nov 5, 2024

A more complete example showing how to set the help text and metavar (and presumably any other property familiar to argparse users):

from typing import Annotated
from rich_argparse import RichHelpFormatter
import yapx


def say_hello(
    name: Annotated[
        str, yapx.arg(help="Who or what to greet?", metavar="NAME")
    ] = "World",
):
    print(f"Hello {name}")


yapx.run(say_hello, formatter_class=RichHelpFormatter)

And the output (right cropped):

Screenshot 2024-11-05 at 20 39 21

@peterjc
Copy link
Author

peterjc commented Nov 5, 2024

I've only just realized that this works "out of the box", if rich-argparse is installed, then it gets used automatically. Nice!

from rich_argparse import RawTextRichHelpFormatter as RawTextHelpFormatter

I guess that means there is no need for an example using RichHelpFormatter explicitly.

@fresh2dev
Copy link
Owner

You got it 👍 I'll make this capability more clear in the docs before I cut the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants