Skip to content

Polishing --help output #4132

@epage

Description

@epage

We are looking to polish the help as part of the v4 release since some parts of an applications help might be dependent on how clap renders things (e.g. to match clap's ALL CAPS help headings, a user might put theirs in ALL CAPS).

So far we have made the following changes:

  • The greens and yellows are gone, instead using bold, underline, and dimmed: PR 4117 though some more work might be needed to enable colored help, depending on the needs
  • Reduce the ALL CAPS: PR 4123
    • See PR for screenshot
    • ARGS and OPTIONS matched the usage and worked as non-colored headings but it feels a bit unpolished
    • I was hard pressed to find other CLIs that do this
    • All caps mirrors man pages
    • Mixed with underlining, it can be hard to see the bottom of "y", "g", etc.
    • Users can rollback to the old behavior with Command::help_template, Command:subcommand_help_heading, and Arg::help_heading
  • List subcommands before args/options: PR 4125
    • See PR for screenshot
    • At the end represents where someone might put it in the usage compared to everything else but generally a user's primary focus is on the subcommand they are going to call so that is where the help's focus should be
    • Users can rollback to the old behavior with Command::help_template
  • List of positional Arguments use [] for optional PR 4144
  • Always show optional positional arguments in usage, rather than collapsing them PR 4151
    • Generally there will be few enough positional arguments that this shouldn't be a big deal
    • Optional flags/options can be more numerous and clog up the usage, making it impossible to deal with (e.g. git)
  • Renaming SUBCOMMAND value name and Subcommand section headers to COMMAND and Command: PR 4155
    • "Subcommand" looks weird to me
    • Hard pressed to find other CLIs that do this
    • Users can rollback to the old behavior with Command::subcommand_help_heading and Command::subcommand_value_name
  • Hint to the user the difference between -h and --help: PR 4159
  • Remove <name> <verson> from the start of --help: PR 4160
    • It takes up precious vertical space but doesn't seem justified, especially when --version exists and when a subcommand doesn't have a version, it feels out of place (see cargo check -h)
    • Again, hard pressed to find other CLIs that do this
    • This does leave where to put authors if people specify them
    • Since all help is rendered from a template, this runs into problems when Command::about is unspecified as it leaves a blank line at the top of the help. fix(help): Always trim output #4156 resolves that
    • Users can rollback to the old behavior with Command::help_template
  • Collapse usage to one line PR 4188
  • Reduce blank lines when overflowing short help onto next line PR 4190
  • Reduce indentation from 4 to 2 to reduce the chance of wrapping PR 4192
    • flags/options already have a lot of whitespace, we probably don't need as much everywhere
    • Inspired by podman -h
    • While refactor(help): Reduce magic numbers for indentation #4161 will make it easier to do on the implementation side, I'm losing steam and don't want to go update all of those tests

Rejected

  • Some CLIs put Usage before the <about> and collapse it to Usage: <usage> if its a single line (e.g. find --help)
    • Putting usage closer to the arguments seems better
    • Otherwise, the difference seems trivial without a reason to go one way or the other
  • Should Arguments and Options be under a single heading by default?
    • I feel like there is a distinct enough difference in how they are used to call them out separately
    • A user can force them to be merged via Arg::help_heading

Future improvements

Note: While I mentioning non-clap CLIs, I want to be clear that we don't just want to conform to what is out there. We should be aiming to make the defaults as polished as possible which can include taking inspiration from others.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-helpArea: documentation, including docs.rs, readme, examples, etc...C-enhancementCategory: Raise on the bar on expectationsS-waiting-on-designStatus: Waiting on user-facing design to be resolved before implementing

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions