You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
first things first: Thanks Armin, David, and the whole community for conceiving and maintaining the excellent Click toolkit.
It feels like we have been looking for a solution to display help text from a Python docstring verbatim for a long time, and apparently missed to discover the documentation about preventing rewrapping, and GH-56.
importtextwrapdefdocstring_format_verbatim(text: str) ->str:
""" Format docstring to be displayed verbatim as a help text by Click. - https://click.palletsprojects.com/en/8.1.x/documentation/#preventing-rewrapping - https://github.com/pallets/click/issues/56 """text=textwrap.dedent(text)
lines= []
forlineintext.splitlines():
is_empty_line=line.strip() ==""ifis_empty_line:
lines.append("\b")
else:
lines.append(line)
return"\n".join(lines)
We hope this recipe helps others who are in the same situation. Please let us know if we missed any feature already available within Click, which would make this workaround obsolete. Thank you again!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Hi there,
first things first: Thanks Armin, David, and the whole community for conceiving and maintaining the excellent Click toolkit.
It feels like we have been looking for a solution to display help text from a Python docstring verbatim for a long time, and apparently missed to discover the documentation about preventing rewrapping, and GH-56.
The suggestion to use the
\b
escape marker saved our day, so we generalized the idea at earthobservations/wetterdienst@c086fc1e4f3:To be used like:
@click.group("acme", help=docstring_format_verbatim(acme_help.__doc__))
We hope this recipe helps others who are in the same situation. Please let us know if we missed any feature already available within Click, which would make this workaround obsolete. Thank you again!
With kind regards,
Andreas.
Beta Was this translation helpful? Give feedback.
All reactions