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

Add sections to allow some customisation of help layout #2196

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

shadowspawn
Copy link
Collaborator

@shadowspawn shadowspawn commented May 18, 2024

Pull Request

I wanted to give this a try, but not sure it adds enough value or is easy enough to use. Opening a draft with proof of concept.

Problem

It isn't convenient to customise the order of sections in the Help.

See #1870

Solution

Create "sections" in formatHelp and call visibleSections which can be overridden to customise the list. Some possible use cases:

  • reorder sections
  • hide sections
  • alter section titles, like make bold or all capitals
  • add own (pre-formatted) sections, like "Environment Variables" or "Examples"
  • (maybe) replace single-line Usage with multi-line usages

Example client code to put options after commands:

program.configureHelp({
  visibleSections: (sections) => {
    // Hide empty sections.
    const visible = sections.filter((section) => !!section.body);
    // Reorder sections.
    const order = ['usage', 'description', 'arguments', 'commands', 'options', 'globalOptions'];
    return visible.sort((a, b) => {
      return order.indexOf(a.name) - order.indexOf(b.name);
    });
  }
});

ChangeLog

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.

None yet

1 participant