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

clap generates invalid bash completions for ArgEnum #2485

Closed
2 tasks done
ajeetdsouza opened this issue May 20, 2021 · 0 comments · Fixed by #2876
Closed
2 tasks done

clap generates invalid bash completions for ArgEnum #2485

ajeetdsouza opened this issue May 20, 2021 · 0 comments · Fixed by #2876
Labels
A-completion Area: completion generator C-bug Category: Updating dependencies 💸 $5

Comments

@ajeetdsouza
Copy link
Contributor

Please complete the following tasks

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

Rust Version

rustc 1.52.1 (9bc8c42bb 2021-05-09)

Clap Version

3.0.0-beta.2

Minimal reproducible code

use clap::{ArgEnum, Clap, IntoApp};

#[derive(Clap, Debug)]
pub struct App {
    #[clap(arg_enum)]
    pub shell: Shell,
}

#[derive(ArgEnum, Debug)]
pub enum Shell {
    Bash,
    Fish,
    Zsh,
}

fn main() {
    let mut app = App::into_app();
    clap_generate::generate::<clap_generate::generators::Bash, _>(
        &mut app,
        "play",
        &mut std::io::stdout(),
    );
}

Steps to reproduce the bug with the above code

cargo run

Actual Behaviour

Assuming a binary name of foo, if I type in fooTab, I get the following completions:

-h         --help     <shell>    -V         --version

Expected Behaviour

The <shell> value is a placeholder, it's not supposed to be used in completions.

I should have gotten the options of bash, fish, zsh instead.

Additional Context

The full generated bash completions are:

_play() {
    local i cur prev opts cmds
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    cmd=""
    opts=""

    for i in ${COMP_WORDS[@]}
    do
        case "${i}" in
            play)
                cmd="play"
                ;;
            
            *)
                ;;
        esac
    done

    case "${cmd}" in
        play)
            opts=" -h -V  --help --version  <shell> "
            if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then
                COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
                return 0
            fi
            case "${prev}" in
                
                *)
                    COMPREPLY=()
                    ;;
            esac
            COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") )
            return 0
            ;;
        
    esac
}

complete -F _play -o bashdefault -o default play

Debug Output

No response

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-bug Category: Updating dependencies 💸 $5
Projects
None yet
2 participants