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

feat: Add help_formatter system wherein help text rendering can be customized. #126

Merged
merged 1 commit into from
Jun 20, 2024

Conversation

DanCardin
Copy link
Owner

@DanCardin DanCardin commented Jun 19, 2024

This enables one to include or exclude things like default values, or choices. Notably changes to include default values in help text by default.

Fixes #125


A kitchen-sink style example of most of the available options, used together.

from cappa import parse, HelpFormatter, Arg

class Command:
    foo: Annotated[str, Arg(help="Help text.", deprecated=True)] = "foo"

def deprecated(arg: Arg) -> str | None:
    if arg.deprecated:
        return "Deprecrated"
    return None

parse(Command, help_formatter=HelpFormatter(arg_format=("{default}", "{help}", deprecated), default_format="(Default `{default}`)")

Resulting in something like (Default foo) Help text. Deprecrated.

…customized.

This enables one to include or exclude things like default values, or choices.
Notably changes to include default values in help text by default.
Copy link
Contributor

@euri10 euri10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read that quite quicklu, I had just one comment, I'll try test it later today to get more of a feel for it, but so far I love it, simple

docs/source/help.md Show resolved Hide resolved
tests/help/test_help_formatter.py Show resolved Hide resolved
@DanCardin DanCardin merged commit 23aeeb1 into main Jun 20, 2024
7 checks passed
@DanCardin DanCardin deleted the dc/default-help branch June 20, 2024 17:55
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

Successfully merging this pull request may close these issues.

Support automatic inclusion of default value into help text
2 participants