Option Groups
Options can be grouped together in the help output by using the group method. This will also affect generated documentation. The sortOrder parameter can be used to control the order in which groups are displayed. Lower values will be displayed first. If two groups have the same sortOrder, they will be sorted alphabetically.
Options can be placed in a group in one of 2 ways:
- An explicit call to
.groupas part of the command's builder function. - By passing a
groupproperty in the option definition.
1 FILESTry in Playground
All Example Files
FILE EXPLORER
option-groups.ts
1import { cli } from 'cli-forge';
2
3const myCLI = cli('demo', {
4 builder: (args) =>
5 args
6 .option('firstName', {
7 type: 'string',
8 description: 'The name to say hello to',
9 })
10 .option('lastName', {
11 type: 'string',
12 description: 'The last name to say hello to',
13 })
14 .option('age', {
15 type: 'number',
16 description: 'The age of the person',
17 })
18 .option('street', {
19 type: 'string',
20 description: 'The street where the person lives',
21 group: 'address',
22 })
23 .option('city', {
24 type: 'string',
25 description: 'The city where the person lives',
26 group: 'address',
27 })
28 .group('basic-info', ['firstName', 'lastName', 'age']),
29 handler: (_args) => {
30 // not important
31 },
32});
33
34if (require.main === module) myCLI.forge();
35