Skip to content

Improve wrong flag help#16427

Merged
fdncred merged 1 commit intonushell:mainfrom
kaathewisegit:flag-help
Aug 13, 2025
Merged

Improve wrong flag help#16427
fdncred merged 1 commit intonushell:mainfrom
kaathewisegit:flag-help

Conversation

@kaathewisegit
Copy link
Copy Markdown
Contributor

@kaathewisegit kaathewisegit commented Aug 13, 2025

Description

Currently, when Nushell encounters an unknown flag, it prints all options in the help string. This is pretty verbose and uses the formatted_flags signature method, which isn't used anywhere else. This commit refactors the parser to use did_you_mean instead, which only suggest one closest option or sends the user to help if nothing close is found.

Release notes summary - What our users need to know

Improved error messages for misspelled flags

Previously, the help text for a missing flag would list all of them, which could get verbose on a single line:

~> ls --full-path
Error: nu::parser::unknown_flag

  × The `ls` command doesn't have flag `full-path`.
   ╭─[entry #8:1:4]
 1 │ ls --full-path
   ·    ─────┬─────
   ·         ╰── unknown flag
   ╰────
  help: Available flags: --help(-h), --all(-a), --long(-l), --short-names(-s), --full-paths(-f), --du(-d), --directory(-D), --mime-type(-m), --threads(-t). Use
        `--help` for more information.

The new error message only suggests the closest flag:

> ls --full-path
Error: nu::parser::unknown_flag

  × The `ls` command doesn't have flag `full-path`.
   ╭─[entry #23:1:4]
 1 │ ls --full-path
   ·    ─────┬─────
   ·         ╰── unknown flag
   ╰────
  help: Did you mean: `--full-paths`?

Closes #16418

@github-actions github-actions bot added the A:parser Issues related to parsing label Aug 13, 2025
@fdncred
Copy link
Copy Markdown
Contributor

fdncred commented Aug 13, 2025

ya, 'did you mean' is probably better. thanks!

@fdncred fdncred merged commit 7133a04 into nushell:main Aug 13, 2025
16 checks passed
@github-actions github-actions bot added this to the v0.107.0 milestone Aug 13, 2025
@132ikl 132ikl added notes:ready The "Release notes summary" section of this PR is ready to be included in our release notes. notes:other Include the release notes summary in the "Other changes" section labels Aug 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A:parser Issues related to parsing notes:other Include the release notes summary in the "Other changes" section notes:ready The "Release notes summary" section of this PR is ready to be included in our release notes.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

formatted_flags always prints all flags

3 participants