Skip to content

Improve wrong flag help - #16427

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

fdncred merged 1 commit into
nushell:mainfrom
kaathewisegit:flag-help

Conversation

@kaathewisegit

@kaathewisegit kaathewisegit commented Aug 13, 2025 •

Copy link
Copy Markdown
Contributor

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

fdncred commented Aug 13, 2025

Copy link
Copy Markdown
Contributor

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

@fdncred
fdncred merged commit 7133a04 into nushell:main Aug 13, 2025
@github-actions github-actions Bot added this to the v0.107.0 milestone Aug 13, 2025
@132ikl 132ikl added notes:ready Indicates Ready for Release notes notes:other Noted in "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 Noted in "Other changes" section notes:ready Indicates Ready for Release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

formatted_flags always prints all flags

3 participants