Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/base-cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,14 +129,16 @@ class BaseCommand {
}

fullUsage.push('')
fullUsage.push(`Run "npm help ${name}" for more info`)
const helpName = parentName ? parentName.split(' ')[0] : name
fullUsage.push(`Run "npm help ${helpName}" for more info`)

return fullUsage.join('\n')
}

constructor (npm) {
this.npm = npm
this.commandArgs = null
this.parentName = null

const { config } = this

Expand Down Expand Up @@ -167,7 +169,7 @@ class BaseCommand {
}

get usage () {
return this.constructor.describeUsage
return this.constructor.getUsage(this.parentName)
}

usageError (prefix = '') {
Expand Down
3 changes: 2 additions & 1 deletion lib/npm.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,13 @@ class Npm {

// Check if help is requested for the subcommand
if (this.config.get('usage')) {
const parentName = commandPath[0]
const parentName = commandPath.join(' ')
return output.standard(SubCommand.getUsage(parentName))
}

// Create subcommand instance and recurse
const subcommandInstance = new SubCommand(this)
subcommandInstance.parentName = commandPath.join(' ')
const subcommandArgs = args.slice(1) // Remove subcommand name from args
const subcommandPath = [...commandPath, subcommandName]

Expand Down
12 changes: 6 additions & 6 deletions tap-snapshots/test/lib/commands/install.js.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ silly logfile done cleaning log files
verbose stack Error: The developer of this package has specified the following through devEngines
verbose stack Invalid devEngines.runtime
verbose stack Invalid name "nondescript" does not match "node" for "runtime"
verbose stack at Install.checkDevEngines ({CWD}/lib/base-cmd.js:247:27)
verbose stack at MockNpm.execCommandClass ({CWD}/lib/npm.js:281:7)
verbose stack at Install.checkDevEngines ({CWD}/lib/base-cmd.js:249:27)
verbose stack at MockNpm.execCommandClass ({CWD}/lib/npm.js:282:7)
verbose stack at MockNpm.exec ({CWD}/lib/npm.js:182:9)
error code EBADDEVENGINES
error EBADDEVENGINES The developer of this package has specified the following through devEngines
Expand Down Expand Up @@ -199,8 +199,8 @@ warn EBADDEVENGINES }
verbose stack Error: The developer of this package has specified the following through devEngines
verbose stack Invalid devEngines.runtime
verbose stack Invalid name "nondescript" does not match "node" for "runtime"
verbose stack at Install.checkDevEngines ({CWD}/lib/base-cmd.js:247:27)
verbose stack at MockNpm.execCommandClass ({CWD}/lib/npm.js:281:7)
verbose stack at Install.checkDevEngines ({CWD}/lib/base-cmd.js:249:27)
verbose stack at MockNpm.execCommandClass ({CWD}/lib/npm.js:282:7)
verbose stack at MockNpm.exec ({CWD}/lib/npm.js:182:9)
error code EBADDEVENGINES
error EBADDEVENGINES The developer of this package has specified the following through devEngines
Expand All @@ -225,8 +225,8 @@ silly logfile done cleaning log files
verbose stack Error: The developer of this package has specified the following through devEngines
verbose stack Invalid devEngines.runtime
verbose stack Invalid name "nondescript" does not match "node" for "runtime"
verbose stack at Install.checkDevEngines ({CWD}/lib/base-cmd.js:247:27)
verbose stack at MockNpm.execCommandClass ({CWD}/lib/npm.js:281:7)
verbose stack at Install.checkDevEngines ({CWD}/lib/base-cmd.js:249:27)
verbose stack at MockNpm.execCommandClass ({CWD}/lib/npm.js:282:7)
verbose stack at MockNpm.exec ({CWD}/lib/npm.js:182:9)
error code EBADDEVENGINES
error EBADDEVENGINES The developer of this package has specified the following through devEngines
Expand Down
1 change: 1 addition & 0 deletions test/lib/commands/stage/approve.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ t.test('throws usageError without stage-id', async t => {
})
await t.rejects(npm.exec('stage', ['approve']), {
code: 'EUSAGE',
message: /npm stage approve <stage-id>/,
})
})

Expand Down