Skip to content

Commit be2960a

Browse files
committed
fix: no longer include default command when listing subcommands
1 parent 68092dc commit be2960a

File tree

3 files changed

+10
-39
lines changed

3 files changed

+10
-39
lines changed

src/discover.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ export async function discoverCommands(
695695
// ! This next line excludes aliases and positionals in an attempt to
696696
// ! address yargs bugs around help text output. See the docs for details.
697697
['$0'],
698-
config.description,
698+
false,
699699
makeVanillaYargsBuilder(programs.helper, config, 'first-pass'),
700700
async (parsedArgv) => {
701701
const debug_ = debug.extend('helper');

test/helpers.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,11 @@ export function getFixturePath(fixture: string | string[]) {
77
export function expectedCommandsRegex(
88
childCommands: (string | [command: string, descriptionRegex: string])[],
99
parentFullName = require(`./fixtures/package.json`).name,
10-
parentDescriptionRegex?: string,
1110
childDescriptionRegex = '[A-Z]',
1211
includeFinalNewline = true
1312
) {
1413
return new RegExp(
1514
'Commands:\\n\\s+' +
16-
parentFullName +
17-
`\\s+${parentDescriptionRegex ?? childDescriptionRegex}[^\\n]*${
18-
parentDescriptionRegex ? '' : '\\s+\\[default][^\\n]*'
19-
}\\n` +
2015
childCommands
2116
.map(
2217
(cmd) =>

test/unit-index.test.ts

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2244,12 +2244,7 @@ describe('<command module auto-discovery>', () => {
22442244

22452245
expect(logSpy.mock.calls[0]).toStrictEqual([
22462246
expect.stringMatching(
2247-
expectedCommandsRegex(
2248-
['n'],
2249-
'nsf',
2250-
'Root program.+\\s+\\[default]\\s+\\[deprecated]',
2251-
'Parent program.+\\s+\\[deprecated]'
2252-
)
2247+
expectedCommandsRegex(['n'], 'nsf', 'Parent program.+\\s+\\[deprecated]')
22532248
)
22542249
]);
22552250

@@ -2258,7 +2253,6 @@ describe('<command module auto-discovery>', () => {
22582253
expectedCommandsRegex(
22592254
[['f', 'Child program.+\\s+\\[deprecated]'], 's', 't'],
22602255
'nsf n',
2261-
'Parent program.+\\s+\\[default]\\s+\\[deprecated]',
22622256
'Child program.+\\s+\\[(?!deprecated)[^\\n]*]'
22632257
)
22642258
)
@@ -2278,10 +2272,6 @@ describe('<command module auto-discovery>', () => {
22782272

22792273
expect(errorSpy).not.toHaveBeenCalled();
22802274

2281-
expect(logSpy.mock.calls).toStrictEqual([
2282-
[expect.stringContaining('[deprecated: this is a deprecation message!]')]
2283-
]);
2284-
22852275
expect(logSpy.mock.calls).toStrictEqual([
22862276
[expect.stringContaining('[deprecated: deprecation message 2]')]
22872277
]);
@@ -2303,13 +2293,11 @@ describe('<command module auto-discovery>', () => {
23032293
expect(bf_util.isNullArguments(parentResult)).toBeTrue();
23042294

23052295
expect(logSpy.mock.calls[0]).toStrictEqual([
2306-
expect.stringMatching(expectedCommandsRegex(['n'], 'nsf', 'Root', 'Parent'))
2296+
expect.stringMatching(expectedCommandsRegex(['n'], 'nsf', 'Parent'))
23072297
]);
23082298

23092299
expect(logSpy.mock.calls[1]).toStrictEqual([
2310-
expect.stringMatching(
2311-
expectedCommandsRegex(['f', 's', 't'], 'nsf n', 'Parent', 'Child')
2312-
)
2300+
expect.stringMatching(expectedCommandsRegex(['f', 's', 't'], 'nsf n', 'Child'))
23132301
]);
23142302
});
23152303
});
@@ -2331,15 +2319,11 @@ describe('<command module auto-discovery>', () => {
23312319
expect(bf_util.isNullArguments(childResult)).toBeTrue();
23322320

23332321
expect(logSpy.mock.calls[0]).toStrictEqual([
2334-
expect.stringMatching(
2335-
/Commands:\n\s+test\s+\[default]\n\s+test nested\n\nOptions:/
2336-
)
2322+
expect.stringMatching(/Commands:\n\s+test nested\n\nOptions:/)
23372323
]);
23382324

23392325
expect(logSpy.mock.calls[1]).toStrictEqual([
2340-
expect.stringMatching(
2341-
/Commands:\n\s+test nested\s+\[default]\n\s+test nested child\n\nOptions:/
2342-
)
2326+
expect.stringMatching(/Commands:\n\s+test nested child\n\nOptions:/)
23432327
]);
23442328

23452329
expect(logSpy.mock.calls[2]).toStrictEqual([
@@ -2466,7 +2450,6 @@ describe('<command module auto-discovery>', () => {
24662450
expectedCommandsRegex(
24672451
['s-p-a-c-e-d-name', 'spaced-name'],
24682452
'badly-named-package',
2469-
'',
24702453
''
24712454
)
24722455
)
@@ -2476,7 +2459,6 @@ describe('<command module auto-discovery>', () => {
24762459
expectedCommandsRegex(
24772460
['bad-ly-name-d'],
24782461
'badly-named-package spaced-name',
2479-
'',
24802462
''
24812463
)
24822464
)
@@ -2842,12 +2824,12 @@ describe('<command module auto-discovery>', () => {
28422824
expect(logSpy.mock.calls).toStrictEqual([
28432825
[
28442826
expect.stringMatching(
2845-
/Commands:\n\s+nsf\s+Root program description text\s+\[default] \[deprecated]\n\s+nsf n\s+Parent program description text\s+\[aliases: parent, p] \[deprecated]\n\nOptions:/
2827+
/Commands:\n\s+nsf n\s+Parent program description text\s+\[aliases: parent, p] \[deprecated]\n\nOptions:/
28462828
)
28472829
],
28482830
[
28492831
expect.stringMatching(
2850-
/Commands:\n\s+nsf n\s+Parent program description text\s+\[default] \[deprecated]\n\s+nsf n f\s+Child program description text\s+\[aliases: child-1] \[deprecated]\n\s+nsf n s\s+Child program description text\s+\[aliases: child-2]\n\s+nsf n t\s+Child program description text\s+\[aliases: child-3]\n\nOptions:/
2832+
/Commands:\n\s+nsf n f\s+Child program description text\s+\[aliases: child-1] \[deprecated]\n\s+nsf n s\s+Child program description text\s+\[aliases: child-2]\n\s+nsf n t\s+Child program description text\s+\[aliases: child-3]\n\nOptions:/
28512833
)
28522834
],
28532835
[expect.not.stringContaining('Commands:')]
@@ -3154,7 +3136,7 @@ describe('<command module auto-discovery>', () => {
31543136
await bf.runProgram(getFixturePath('nested-same-names'), '--help');
31553137

31563138
expect(logSpy.mock.calls).toStrictEqual([
3157-
[expect.stringMatching(expectedCommandsRegex(['conflict'], 'conflict', '', ''))]
3139+
[expect.stringMatching(expectedCommandsRegex(['conflict'], 'conflict', ''))]
31583140
]);
31593141
});
31603142
});
@@ -3274,7 +3256,6 @@ describe('<command module auto-discovery>', () => {
32743256
['no-conflict', '\\[aliases: alias3]']
32753257
],
32763258
'name',
3277-
'',
32783259
''
32793260
)
32803261
)
@@ -3292,12 +3273,7 @@ describe('<command module auto-discovery>', () => {
32923273
expect(logSpy.mock.calls).toStrictEqual([
32933274
[
32943275
expect.stringMatching(
3295-
expectedCommandsRegex(
3296-
['five', 'four', 'one', 'three', 'two'],
3297-
'alpha',
3298-
'',
3299-
''
3300-
)
3276+
expectedCommandsRegex(['five', 'four', 'one', 'three', 'two'], 'alpha', '')
33013277
)
33023278
]
33033279
]);

0 commit comments

Comments
 (0)