Skip to content

fix: show full option descriptions in --help output#9233

Closed
lovasoa wants to merge 1 commit intonpm:latestfrom
lovasoa:fix/help-description-truncation
Closed

fix: show full option descriptions in --help output#9233
lovasoa wants to merge 1 commit intonpm:latestfrom
lovasoa:fix/help-description-truncation

Conversation

@lovasoa
Copy link
Copy Markdown

@lovasoa lovasoa commented Apr 14, 2026

Option descriptions in --help output were truncated to the first line. For example, npm version --help showed:

$ npm version --help
  --allow-same-version
    Prevents throwing an error when `npm version` is used to set the new

instead of the complete text:

$ npm version --help
  --allow-same-version
    Prevents throwing an error when `npm version` is used to set the new
    version to the same value as the current version.

This affected all commands, not just version.

Cause: getUsage() in lib/base-cmd.js used .split(n)[0] on each description, discarding everything after the first newline. Since descriptions are multi-line template literals, this cut most of them off mid-sentence.

Fix: Join all lines of the description into a single string instead of taking only the first line.

The help text for command options was truncated to the first line of each
multi-line description. For example, `npm version --help` showed:

  --allow-same-version
    Prevents throwing an error when `npm version` is used to set the new

Instead of the full description. This affected all commands.

The cause was `.split('\n')[0]` in base-cmd.js getUsage(), which discarded
everything after the first newline. Fix by joining all lines into a single
string.
@lovasoa lovasoa requested a review from a team as a code owner April 14, 2026 08:38
@lovasoa lovasoa mentioned this pull request Apr 14, 2026
@owlstronaut
Copy link
Copy Markdown
Contributor

Okay, I think this was actually an intentional design decision. Some of those descriptions are very long and --help is meant to give you a quick summary - i don't think we want full descriptions in there anyway. npm help version would give you the full text if that is what you wanted, i don't think showing everything here is the answer.

@lovasoa
Copy link
Copy Markdown
Author

lovasoa commented Apr 14, 2026

Sentences are cut in the middle without any explanation. Maybe the output should at least let the use know why and how to get the full description ?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants