epage / clapng

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

clap_generate: zsh broken with two multi length arguments #238

Open epage opened 2 years ago

epage commented 2 years ago

Issue by Morganamilo Saturday Nov 13, 2021 at 22:47 GMT Originally opened as https://github.com/clap-rs/clap/issues/3022


Please complete the following tasks

Rust Version

rustc 1.58.0-nightly (8b09ba6a5 2021-11-09)

Clap Version

3.0.0-beta.5

Minimal reproducible code

use clap::{App, IntoApp, Parser};
use clap_generate::{generate, Shell};
use std::io::stdout;

#[derive(Parser)]
pub struct Args {
    pub targets: Vec<String>,
    #[clap(required = true, raw = true)]
    pub files: Vec<String>,
}

fn main() {
    let mut app: App = Args::into_app();
    generate(Shell::Zsh, &mut app, "bug", &mut stdout());
}

Steps to reproduce the bug with the above code

With the completion installed:

% command <tab>
_arguments:comparguments:325: doubled rest argument definition: *::file -- Files to search for:

Actual Behaviour

So I have a program that has a usage like this: program: <targets>... -- <files>...

The zsh completion seems to really not like this and spits out an error when tab is hit:

_arguments:comparguments:325: doubled rest argument definition: *::file -- Files to search for:

The completion generated is:

#compdef bug

autoload -U is-at-least

_bug() {
    typeset -A opt_args
    typeset -a _arguments_options
    local ret=1

    if is-at-least 5.2; then
        _arguments_options=(-s -S -C)
    else
        _arguments_options=(-s -C)
    fi

    local context curcontext="$curcontext" state line
    _arguments "${_arguments_options[@]}" \
'-h[Print help information]' \
'--help[Print help information]' \
'*::targets:' \
'*::files:' \
&& ret=0
}

(( $+functions[_bug_commands] )) ||
_bug_commands() {
    local commands; commands=()
    _describe -t commands 'bug commands' commands "$@"
}

_bug "$@"%

Expected Behaviour

Don't be broken

Additional Context

No response

Debug Output

No response

epage commented 2 years ago

Comment by epage Sunday Nov 14, 2021 at 01:52 GMT


Thanks for reporting this!

One challenge with completions is we have to effectively re-implement clap's argument parsing for each shell we support. Example of other issues that look like they stem from this:

This is making me think that https://github.com/clap-rs/clap/issues/1232 is even more important so we can share parsing logic between different shells and clap and more easily test it.

epage commented 2 years ago

Comment by pksunkara Sunday Nov 14, 2021 at 02:41 GMT


To be more explicitly clear, it's not the parsing logic we need to share but rather the parsing requirements.