clap icon indicating copy to clipboard operation
clap copied to clipboard

Derive's case conversion removes non-ASCII BMP char

Open Rudxain opened this issue 2 years ago • 1 comments

Please complete the following tasks

Rust Version

1.62.0 (a8314ef7d 2022-06-27)

Clap Version

3.2.12

Minimal reproducible code

use clap::Parser;

#[derive(Parser)]
#[clap()]
struct Cli {
	#[clap(long, action)]
	olé: bool,
	#[clap(long = "olé!", action)]
	olé1: bool,
	#[clap(long, action)]
	olé2: bool
}

fn main() {
	let cli = Cli::parse();
	println!("{} {} {}", cli.olé, cli.olé1, cli.olé2);
}

Steps to reproduce the bug with the above code

cargo run -- --olé2
cargo run -- -h
cargo run -- --olé

Actual Behaviour

cargo run -- -h output:

clap_bug 

USAGE:
    clap_bug [OPTIONS]

OPTIONS:
    -h, --help    Print help information
        --ol      
        --ol-2    
        --olé!

It affects both the help and the argument recognition. --ol is recognized, but not --olé, same happens to --olé2

Expected Behaviour

--olé, --olé!, and --olé2should be recognized as-is

Additional Context

No response

Debug Output

No response

Rudxain avatar Jul 19 '22 07:07 Rudxain

Whats happening is that the derive will implicitly convert field names from snake_case to kebab-case. This is what is dropping the characters and is why an explicit long works.

For example, the following works for me

#!/usr/bin/env -S rust-script --debug

//! ```cargo
//! [dependencies]
//! clap = { version = "3.2.8", features = ["derive"] }
//! ```

use clap::Parser;

#[derive(Parser)]
#[clap(rename_all = "verbatim")]
struct Cli {
    #[clap(long, action)]
    olé: bool,
    #[clap(long = "olé!", action)]
    olé1: bool,
    #[clap(long, action)]
    olé2: bool,
}

fn main() {
    let cli = Cli::parse();
    println!("{} {} {}", cli.olé, cli.olé1, cli.olé2);
}

epage avatar Jul 19 '22 14:07 epage