clap
clap copied to clipboard
Derive's case conversion removes non-ASCII BMP char
Please complete the following tasks
- [X] I have searched the discussions
- [X] I have searched the open and rejected issues
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é2
should be recognized as-is
Additional Context
No response
Debug Output
No response
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);
}