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: Fix fish shell completion bug that occurs when ValueEnum is the only one #5143

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

gw31415
Copy link

@gw31415 gw31415 commented Sep 26, 2023

Bug to be fixed

This PR is about bug of fish shell completion.

Here is an example. The correct completion candidate is hoge, but \{hoge is actually completed.

$ example --action \{hoge       # extra left brace

This occurs when the ValueEnum has only one candidate.

Code to reproduce the bug

use std::io;

use clap::{CommandFactory, Parser, ValueEnum};
use clap_complete::{self, generate, Shell};

#[derive(Parser)]
#[command(name = "example")]
struct Args {
    #[arg(long)]
    action: Option<Action>,
}

#[derive(ValueEnum, Clone)]
enum Action {
    Hoge,
}

fn main() {
    Args::parse();
    let mut cmd = Args::command();
    let name = cmd.get_name().to_string();
    generate(Shell::Fish, &mut cmd, name, &mut io::stdout());
}
  • The symptom
$ example --action \{hoge       # extra left brace
  • Generated completion file
complete -c example -l action -r -f -a "{hoge	''}"
complete -c example -s h -l help -d 'Print help'

@epage
Copy link
Member

epage commented Sep 26, 2023

Can you add a test case to https://github.com/clap-rs/clap/blob/master/clap_complete/tests/testsuite/fish.rs#L161 ?

Ideally

  • First commit modifies the test, with the current buggy behavior
  • Second commit fixes the code and updates the test with the desired behavior

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.

None yet

2 participants