fix: show full parent command path in subcommand usage errors by shaanmajid · Pull Request #9404 · npm/cli · GitHub
Skip to content

fix: show full parent command path in subcommand usage errors - #9404

Merged
owlstronaut merged 3 commits into
npm:latestfrom
shaanmajid:fix/subcommand-usage-path
Jun 2, 2026
Merged

owlstronaut merged 3 commits into
npm:latestfrom
shaanmajid:fix/subcommand-usage-path

Conversation

@shaanmajid

Copy link
Copy Markdown

Summary

  • Subcommand runtime usage errors (e.g., npm stage approve without a <stage-id>) rendered the bare subcommand name (e.g., npm approve <stage-id>) and Run "npm help approve" for more info -- pointing at a command and help page that don't exist.
  • The subcommand instance now carries its parent command name, so usage output and usageError render the full path (npm stage approve <stage-id>) and point to the real help page (npm help stage)

This fix applies to npm stage and npm trust.

Implementation

  • lib/npm.js: set parentName on the subcommand instance during dispatch (and use the full joined path on the --help branch for parity).
  • lib/base-cmd.js: the instance usage getter threads parentName into getUsage, and the help footer resolves to the top-level documented command.

References

Fixes #9403

@shaanmajid
shaanmajid requested review from a team as code owners May 25, 2026 20:48
@swarnim-dev

Copy link
Copy Markdown

@shaanmajid

Copy link
Copy Markdown
Author

CI failures were from stale snapshot; should be fixed with 40655c0

@owlstronaut
owlstronaut merged commit fe41ae7 into npm:latest Jun 2, 2026
22 checks passed
@github-actions

github-actions Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Subcommand usage errors show the wrong command path (e.g. "npm approve" instead of "npm stage approve")

3 participants