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

Implement a custom HelpFormatter #14

Closed
janluke opened this issue Apr 21, 2021 · 1 comment
Closed

Implement a custom HelpFormatter #14

janluke opened this issue Apr 21, 2021 · 1 comment
Labels
enhancement New feature or request
Milestone

Comments

@janluke
Copy link
Owner

janluke commented Apr 21, 2021

Motivations

  1. Cloup relies on a hack (padding) to align multiple sections because click.HelpFormatter doesn't support it.

  2. Click 7 adds an extra empty line only after options with a long description taking multiple lines. This makes vertical spacing inconsistent, especially when using Cloup. This behaviour was removed in Click 8 on my request.

  3. Customizing the help is unnecessarily difficult in Click, especially in Click 7. There's work in progress but the new formatting system won't be released in Click 8.0.

  4. The formatting code (especially HelpFormatter.write_dl) has several issues and there's no point in fixing them in Click since they are going to redesign the entire formatting system.

Requirements

  • Should support alignment of multiple sections; this can be implemented (at the core) by adding col1_width=None arguments to write_dl
  • Should have more attributes for customization, like col1_max_width (called col_max in write_dl), col_spacing.
  • Optionally, implements a row_sep attribute that is written after each row of a definition list; this allows clients to separate rows with an empty line, for example.
  • If there's not enough space for a 2nd column (min 15-20 chars), write a definition list as a linear list with the option.help printed always under the opts, indented.
  • Improve help readability when the available width for the second column is small.
  • (Help page styling and theming #25) Help styling and theming.

Changes to support the feature

Using a custom help formatter will require other structural changes:

  • (Implement a custom Context and add align_option_groups and align_sections attrs #15) implement of a custom Context that uses the custom HelpFormatter; add a BaseCommand(click.Command) that uses the custom Context and make it the parent class of Command and MultiCommand.
  • make OptionGroupMixin and SectionMixin use the custom formatter
  • add an attribute formatter_settings to both Context and BaseCommand to support easy customization.
@janluke janluke added this to the v0.8.0 milestone Apr 21, 2021
@janluke janluke added the enhancement New feature or request label Apr 21, 2021
@janluke
Copy link
Owner Author

janluke commented May 11, 2021

I decided to stay compatible with Click by subclassing HelpFormatter for now. To allow styling of stuff like option metavar, default values and envvars, I'd need to subclass Option and move even more formatting logic to the formatter so that it can deal with options and commands directly (rather than with generic "rows" and "sections"). Let's keep it simple for now.

@janluke janluke closed this as completed May 11, 2021
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

No branches or pull requests

1 participant