Skip to content

Commit a9d242b

Browse files
authored
fix: include all subcommands on main command help (#9099)
1 parent 5b7c0cc commit a9d242b

File tree

6 files changed

+18
-7
lines changed

6 files changed

+18
-7
lines changed

docs/lib/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ const getCommandByDoc = (docFile, docExt, commandLoader = defaultCommandLoader)
9494
name,
9595
workspaces,
9696
definitions: name === 'npx' ? {} : resolvedDefs,
97-
usage: usage.map(u => `${usagePrefix} ${u}`.trim()).join('\n'),
97+
usage: usage?.map(u => `${usagePrefix} ${u}`.trim()).join('\n'),
9898
}
9999
}
100100

lib/base-cmd.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,15 @@ class BaseCommand {
4343
`${description}`,
4444
'',
4545
'Usage:',
46-
...usage.map(u => `npm ${fullCommandName} ${u}`.trim()),
4746
]
47+
if (usage) {
48+
fullUsage.push(...usage.map(u => `npm ${fullCommandName} ${u}`.trim()))
49+
}
4850

4951
if (this.subcommands) {
52+
for (const sub in this.subcommands) {
53+
fullUsage.push(`npm ${fullCommandName} ${sub} ${this.subcommands[sub].usage}`)
54+
}
5055
fullUsage.push('')
5156
fullUsage.push('Subcommands:')
5257
const subcommandEntries = Object.entries(this.subcommands)

lib/commands/trust/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ const BaseCommand = require('../../base-cmd.js')
33
class Trust extends BaseCommand {
44
static description = 'Create a trusted relationship between a package and a OIDC provider'
55
static name = 'trust'
6+
static usage = null
67

78
static subcommands = {
89
github: require('./github.js'),

tap-snapshots/test/lib/commands/install.js.test.cjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ silly logfile done cleaning log files
134134
verbose stack Error: The developer of this package has specified the following through devEngines
135135
verbose stack Invalid devEngines.runtime
136136
verbose stack Invalid name "nondescript" does not match "node" for "runtime"
137-
verbose stack at Install.checkDevEngines ({CWD}/lib/base-cmd.js:242:27)
137+
verbose stack at Install.checkDevEngines ({CWD}/lib/base-cmd.js:247:27)
138138
verbose stack at MockNpm.execCommandClass ({CWD}/lib/npm.js:292:7)
139139
verbose stack at MockNpm.exec ({CWD}/lib/npm.js:193:9)
140140
error code EBADDEVENGINES
@@ -199,7 +199,7 @@ warn EBADDEVENGINES }
199199
verbose stack Error: The developer of this package has specified the following through devEngines
200200
verbose stack Invalid devEngines.runtime
201201
verbose stack Invalid name "nondescript" does not match "node" for "runtime"
202-
verbose stack at Install.checkDevEngines ({CWD}/lib/base-cmd.js:242:27)
202+
verbose stack at Install.checkDevEngines ({CWD}/lib/base-cmd.js:247:27)
203203
verbose stack at MockNpm.execCommandClass ({CWD}/lib/npm.js:292:7)
204204
verbose stack at MockNpm.exec ({CWD}/lib/npm.js:193:9)
205205
error code EBADDEVENGINES
@@ -225,7 +225,7 @@ silly logfile done cleaning log files
225225
verbose stack Error: The developer of this package has specified the following through devEngines
226226
verbose stack Invalid devEngines.runtime
227227
verbose stack Invalid name "nondescript" does not match "node" for "runtime"
228-
verbose stack at Install.checkDevEngines ({CWD}/lib/base-cmd.js:242:27)
228+
verbose stack at Install.checkDevEngines ({CWD}/lib/base-cmd.js:247:27)
229229
verbose stack at MockNpm.execCommandClass ({CWD}/lib/npm.js:292:7)
230230
verbose stack at MockNpm.exec ({CWD}/lib/npm.js:193:9)
231231
error code EBADDEVENGINES

tap-snapshots/test/lib/docs.js.test.cjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5782,7 +5782,11 @@ exports[`test/lib/docs.js TAP usage trust > must match snapshot 1`] = `
57825782
Create a trusted relationship between a package and a OIDC provider
57835783
57845784
Usage:
5785-
npm trust
5785+
npm trust github [package] --file [--repo|--repository] [--env|--environment] [-y|--yes]
5786+
npm trust gitlab [package] --file [--project|--repo|--repository] [--env|--environment] [-y|--yes]
5787+
npm trust circleci [package] --org-id <uuid> --project-id <uuid> --pipeline-definition-id <uuid> --vcs-origin <origin> [--context-id <uuid>...] [-y|--yes]
5788+
npm trust list [package]
5789+
npm trust revoke [package] --id=<trust-id>
57865790
57875791
Subcommands:
57885792
github
@@ -5805,7 +5809,7 @@ Run "npm trust <subcommand> --help" for more info on a subcommand.
58055809
Run "npm help trust" for more info
58065810
58075811
\`\`\`bash
5808-
npm trust
5812+
58095813
\`\`\`
58105814
58115815
Note: This command is unaware of workspaces.

test/lib/base-cmd.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ t.test('getUsage() with no params and no definitions', async t => {
221221
class TestCommand extends BaseCommand {
222222
static name = 'test-command'
223223
static description = 'Test command description'
224+
static usage = ['']
224225
}
225226

226227
const usage = TestCommand.describeUsage

0 commit comments

Comments
 (0)