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

Help groups for commands and options #1908

Closed
wants to merge 8 commits into from

Conversation

shadowspawn
Copy link
Collaborator

@shadowspawn shadowspawn commented Jul 15, 2023

Problem

Some people with larger programs would like to break up their commands and options into groups in the help. There have not been a lot of requests for this, but it is something I had noticed as a possible enhancement.

See: #374 (comment) #1897

Help groups are common in "big" programs, but big programs often have custom help systems anyway! (e.g. git, npm)

Solution

I am currently trying to implement some of the API ideas in #1897 to see how they go. If I can't decide which one or ones are best, I might open a poll for feedback on preferred approach.

Two caveats from work so far:

  • supporting group for the built-in help option and help command is extra work, except for the "map" api where easy
  • it takes a bit of code to sort out the groups. Want to consider whether worth the extra complexity.

ChangeLog


Still a work in progress, I am coding to try ideas so anything could change. 🛠

What is working currently. Can mix and match.

Map, which implies order of groups displayed, and order of commands and options displayed. Help option and help command are included without special code. Options allow short or long option (or attribute name).

program.commandGroups = new Map([
  ['A Commands:', ['a3', 'a2', 'a1']],
  ['B Commands:', ['b3', 'b2', 'b1']],
  ['Help Commands:', ['help']]
]);

program.optionGroups = new Map([
  ['Animal Options:', ['-r', '--armadillo', '--no-sheep', 'dog', '--no-dog']],
  ['Element Options:', ['--carbon', '-o', '-n']],
  ['Help Options:', ['--help']]
]);

Group specified on command and option. This is nice for setting up everything about a command or option in one place. Small downsides are group specified multiple times and have to build Option.

program
  .command('b99')
  .group('B Commands:')
  .action(() => console.log('Called subcommand'));

program
  .addOption(new Option('-s, --sheep').group('Animal Options:'))

@shadowspawn shadowspawn changed the base branch from master to develop July 15, 2023 00:54
@shadowspawn
Copy link
Collaborator Author

I got everything going, but was not happy with extra properties and extra code. I did not want to offer them all anyway! Started again with support for just helpGroup on Option and Group with extensions for the built-ins.

See #1910

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.

1 participant