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

Redundant code in Zsh completion when there are no subcommands #1142

Closed
segevfiner opened this issue Jan 6, 2018 · 2 comments
Closed

Redundant code in Zsh completion when there are no subcommands #1142

segevfiner opened this issue Jan 6, 2018 · 2 comments
Labels
A-completion Area: completion generator C-enhancement Category: Raise on the bar on expectations

Comments

@segevfiner
Copy link
Contributor

Rust Version

rustc 1.23.0 (766bd11c8 2018-01-01)

Affected Version of clap

2.29.0

Expected Behavior Summary

There shouldn't be redundant code in the generated Zsh completion code.

Actual Behavior Summary

There is some redundant code when there are no sub-commands.

Generated from the sample:

#compdef clap-test

_clap-test() {
    typeset -A opt_args
    local ret=1

    local context curcontext="$curcontext" state line
    _arguments -s -S -C \
'--completions[]' \
'-h[Prints help information]' \
'--help[Prints help information]' \
'-V[Prints version information]' \
'--version[Prints version information]' \
&& ret=0
    
}

(( $+functions[_clap-test_commands] )) ||
_clap-test_commands() {
    local commands; commands=(
        
    )
    _describe -t commands 'clap-test commands' commands "$@"
}
(( $+functions[_clap-test_commands] )) ||
_clap-test_commands() {
    local commands; commands=(
        
    )
    _describe -t commands 'clap-test commands' commands "$@"
}

_clap-test "$@"

Notice the double _clap-test_commands part.

Steps to Reproduce the issue

  1. Build the sample.
  2. Run cargo run -- --completions.
  3. Check the output.

Sample Code or Link to Sample Code

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("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())
    }
}

Debug output

clap-debug.txt

@kbknapp
Copy link
Member

kbknapp commented Jan 9, 2018

@segevfiner since you're already on a roll for these completions PRs, do you want to take a swing at this one? 😄

@kbknapp kbknapp added C-enhancement Category: Raise on the bar on expectations D: intermediate A-completion Area: completion generator labels Jan 9, 2018
@segevfiner
Copy link
Contributor Author

I probaby will 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-completion Area: completion generator C-enhancement Category: Raise on the bar on expectations
Projects
None yet
Development

No branches or pull requests

2 participants