Difference in epilog handling vs main help handling #1400
-
First Check
Commit to Help
Example Codeimport typer
app = typer.Typer(rich_markup_mode="rich")
the_help_string = """
Examples:
1. Bla bla here
2. Bla bla 3 here
"""
help_string_two = """
Other help here
It's very helpful clearly.
"""
epilog_test = """
Test:
1. This
2. Maybe?
"""
@app.command(help=the_help_string, epilog=epilog_test)
def command_one():
pass
@app.command(help=help_string_two)
def command_two_test():
raise ValueError("make it break")
if __name__ == "__main__":
app()DescriptionMy main question is simple: why is the handling for epilog different from the main help string? Typer strips out additional line endings from the epilog, which is not always desirable (especially in the case of wanting to list examples commands with newlines between the example commands to prevent the examples being too densely packed together. Investigation of the code contained in https://github.com/fastapi/typer/blob/master/typer/rich_utils.py shows how this occurs. The main help string is being formatted & handled like this: (inside # Print command / group help if we have some
if obj.help:
# Print with some padding
console.print(
Padding(
Align(
_get_help_text(
obj=obj,
markup_mode=markup_mode,
),
pad=False,
),
(0, 1, 1, 1),
)
)Source: https://github.com/fastapi/typer/blob/master/typer/rich_utils.py#L574 But then the epilog is being handled very differently: # Epilogue if we have it
if obj.epilog:
# Remove single linebreaks, replace double with single
lines = obj.epilog.split("\n\n")
epilogue = "\n".join([x.replace("\n", " ").strip() for x in lines])
epilogue_text = _make_rich_text(text=epilogue, markup_mode=markup_mode)
console.print(Padding(Align(epilogue_text, pad=False), 1))Source: https://github.com/fastapi/typer/blob/master/typer/rich_utils.py#L685 Can we make it configurable so that the epilog does not strip out extra newlines unless the person desires it? I would be quite happy if there was a flag that a user can specify that causes the epilog to be handled the same way that the normal help string is handled in terms of newline stripping. Operating SystemWindows, macOS, Other Operating System DetailsApplies to all operating systems (I've tested on Windows 10/11/RHEL 8) Typer Version0.20.0 Python Version3.11.9 Additional ContextThe only other conversation related to epilog formatting I've found is this one here: #1211 but this seems specifically interested in an additional newline at the end which always gets printed, and that's not overly impactful to what I'm building. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
|
Showing an example of what the output looks like with the line stripping in place (ie the default behaviour): But what I'd like is to have the output actually match what's in the string, where it'd look like this: |
Beta Was this translation helpful? Give feedback.
-
|
Hi @EnigmaticCypher, thanks for the report! I had a look into this and created a PR #1405. If you could check whether that solves your issues, that'd be great. Feel free to leave a review directly on the PR 🙏 |
Beta Was this translation helpful? Give feedback.
Hi @EnigmaticCypher, thanks for the report! I had a look into this and created a PR #1405. If you could check whether that solves your issues, that'd be great. Feel free to leave a review directly on the PR 🙏