Skip to content

Conversation

@nitsky
Copy link
Contributor

@nitsky nitsky commented Oct 30, 2025

In clap_complete_nushell, arguments are written in the order they are added to the Command, not according to the
index they are specified with. If required positional arguments with a lower index are added to the command after
optional positional arguments are added, nushell rejects the generated completion because nushell forbids required
arguments to come after optional arguments.

For example, if positional arguments are defined as:

  • .arg(Arg::new("second").index(2)) (optional)
  • .arg(Arg::new("first").index(1)) (required)

The current output would incorrectly place second? before first, which nushell rejects.

To fix this, I reordered the output so all non-positional arguments are written in their normal order, and then all
positional arguments are written, ordered by their index.

I'm not certain this is the best approach, I would appreciate feedback.

@epage
Copy link
Member

epage commented Oct 30, 2025

Feel free to edit commits to have them how we should review/merge them

@epage
Copy link
Member

epage commented Oct 30, 2025

Also, our preference is to add tests like these in the commit before the fix with them passing, showing the broken behavior. The fix will then update the tests, showing the new behavior.

@nitsky nitsky force-pushed the feat/nushell-completion-arguments-index branch 2 times, most recently from 88ebf44 to 23e16e5 Compare October 30, 2025 13:16
@nitsky nitsky changed the title fix(clap_complete_nushell): order nushell completion arguments by their index fix(clap_complete_nushell): order positional arguments by index Oct 30, 2025
@nitsky
Copy link
Contributor Author

nitsky commented Oct 30, 2025

@epage I apologize for the oversight. I split the change into two commits, one that adds the test, and another that implements the feature and updates the snapshots.

@epage
Copy link
Member

epage commented Oct 30, 2025

Thanks!

CI seems to still be failing

@nitsky nitsky force-pushed the feat/nushell-completion-arguments-index branch from 23e16e5 to 83cbb5b Compare October 30, 2025 23:13
@nitsky
Copy link
Contributor Author

nitsky commented Oct 31, 2025

I fixed CI, I didn't see the nushell test that requires an unstable feature.

@epage
Copy link
Member

epage commented Oct 31, 2025

Thanks!

@epage epage merged commit 6a64a8b into clap-rs:master Oct 31, 2025
25 checks passed
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