Skip to content
This repository has been archived by the owner on Jan 1, 2022. It is now read-only.

clap_generate: zsh broken with two multi length arguments #238

Open
2 tasks done
epage opened this issue Dec 6, 2021 · 2 comments
Open
2 tasks done

clap_generate: zsh broken with two multi length arguments #238

epage opened this issue Dec 6, 2021 · 2 comments

Comments

@epage
Copy link
Owner

epage commented Dec 6, 2021

Issue by Morganamilo
Saturday Nov 13, 2021 at 22:47 GMT
Originally opened as clap-rs/clap#3022


Please complete the following tasks

  • I have searched the discussions
  • I have searched the existing issues

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
Copy link
Owner Author

epage commented Dec 6, 2021

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 clap-rs/clap#1232 is even more important so we can share parsing logic between different shells and clap and more easily test it.

@epage
Copy link
Owner Author

epage commented Dec 6, 2021

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant