clap-rs / clap

A full featured, fast Command Line Argument Parser for Rust
docs.rs/clap
Apache License 2.0
14.22k stars 1.04k forks source link

[nushell] Generates invalid completions when variadic arg is used with last=true arg #5771

Open milesj opened 2 weeks ago

milesj commented 2 weeks ago

Please complete the following tasks

Rust Version

rustc 1.81.0 (eeb90cda1 2024-09-04)

Clap Version

4.5.19

Minimal reproducible code

use clap::Args;
use clap_complete::generate;
use clap_complete_nushell::Nushell;

#[derive(Args)]
pub struct ExampleArgs {
    #[arg(required = true, help = "...")]
    pub id: Vec<String>,

    // after --
    #[arg(last = true, help = "...")]
    pub passthrough: Vec<String>,
}

#[derive(Subcommand)]
pub enum CliCommand {
  #[command(name = "example")
  Example(ExampleArgs),
}

#[derive(Parser)]
pub struct Cli {
  #[command(subcommand)]
  pub command: CliCommand,
}

fn main() {
  let mut app = Cli::command();
  let mut stdio = std::io::stdout();
  generate(Nushell, &mut app, "bin", &mut stdio);
}

Steps to reproduce the bug with the above code

cargo run -- example

Actual Behaviour

It generates a completion that uses ...<arg>: string syntax for both the variadic arg, and the last arg. This results in Nu erroring with "Multiple rest params".

Example: https://cdn.discordapp.com/attachments/974160221452763149/1289506849053343845/image.png?ex=6706ea16&is=67059896&hm=6df6cb538be11ccf5a531f46c2dab73013e965749fe809a95287666b16188803&

Expected Behaviour

This generates a valid completion. We probably want to omit last args entirely.

Additional Context

No response

Debug Output

No response

epage commented 1 week ago

If we have to choose between one, seems fine to drop last.

Note that completions are mostly driven by users so if you want this fixed, doing it yourself is the most likely way for that to happen.

What would help even more is if someone implemented nushell support for #3166 so we'd no longer be limited by what nushell's completion rules support and if something gets implemented for one shell, most likely all shells benefit.