Skip to content

completion: last(true) + subcommands causes 'doubled rest argument' error in Zsh #4898

@clubby789

Description

@clubby789

Please complete the following tasks

Rust Version

rustc 1.71.0-nightly (f9a6b7158 2023-05-05)

Clap Version

4.2.7

Minimal reproducible code

use clap::{CommandFactory, Parser, Subcommand};
use clap_complete::generate;

#[derive(Parser)]
struct Opt {
    #[arg(last(true))]
    pub free_args: Vec<String>,
    #[command(subcommand)]
    command: SubOpt,
}

#[derive(Subcommand)]
enum SubOpt {
    Foo,
    Bar,
}

fn main() {
    let mut cmd = Opt::command();
    let name = cmd.get_name().to_string();
    generate(clap_complete::shells::Zsh, &mut cmd, name, &mut std::io::stdout());
}

Steps to reproduce the bug with the above code

Redirect the output to a file, use source poc.zsh to load it, then enter <app-name> and hit tab.

Actual Behaviour

_arguments:comparguments:327: doubled rest argument definition: *::: :->poc

Expected Behaviour

An error should not occur and completion should work as normal.

Additional Context

I'm unsure if this is related to #4652, but it prevents completion from working at all

Debug Output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-completionArea: completion generatorC-bugCategory: bugE-easyCall for participation: Experience needed to fix: Easy / not much

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions