Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix completion of long option values in Zsh #1141

Merged
merged 2 commits into from
Jan 9, 2018

Conversation

segevfiner
Copy link
Contributor

@segevfiner segevfiner commented Jan 6, 2018

Long options take their argument either in the next word or after an equals sign, but the Zsh completion specified that they take it either in the same word with no separator or in the next word. See the documentation of the Zsh _arguments function for more information.

Sample for testing

extern crate clap;

use std::io;
use clap::{App, Arg, Shell};

fn build_cli() -> App<'static, 'static> {
    App::new("clap-test")
        .arg(Arg::with_name("wat")
            .long("wat")
            .takes_value(true)
            .possible_values(&["foo", "bar"]))
        .arg(Arg::with_name("completions")
            .long("completions"))
}

fn main() {
    let matches = build_cli().get_matches();

    if matches.is_present("completions") {
        build_cli().gen_completions_to("clap-test", Shell::Zsh, &mut io::stdout())
    }

    if let Some(wat) = matches.value_of("wat") {
        println!("{}", wat);
    }
}

Related #850


This change is Reviewable

@mention-bot
Copy link

@segevfiner, thanks for your PR! By analyzing the history of the files in this pull request, we identified @kbknapp to be a potential reviewer.

@segevfiner segevfiner force-pushed the zsh-long-options-completion-fix branch from 61149d7 to 0a394ee Compare January 6, 2018 11:49
Long options take their argument either in the next word or after an
equals sign, but the Zsh completion specified that they take it either
in the same word with no separator or in the next word. See the
documentation of the Zsh _arguments function for more information.
@segevfiner segevfiner force-pushed the zsh-long-options-completion-fix branch from 0a394ee to 46365cf Compare January 6, 2018 12:43
@kbknapp
Copy link
Member

kbknapp commented Jan 9, 2018

Thanks, ZSH completions is definitely an area where my knowledge is lacking and I was learning on the fly. I appreciate this!

@kbknapp kbknapp merged commit 28a55f2 into clap-rs:master Jan 9, 2018
@segevfiner segevfiner deleted the zsh-long-options-completion-fix branch January 9, 2018 21:34
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.

3 participants