(root: &clap::Command, key: &str, display: &str)
| 357 | } |
| 358 | |
| 359 | fn option_spellings(root: &clap::Command, key: &str, display: &str) -> Vec<String> { |
| 360 | let shown = display.split_whitespace().next().unwrap_or_default(); |
| 361 | if !shown.starts_with('-') { |
| 362 | return Vec::new(); |
| 363 | } |
| 364 | |
| 365 | let node = walk_to(root, key); |
| 366 | let short = shown.strip_prefix('-').and_then(|value| { |
| 367 | let mut chars = value.chars(); |
| 368 | let first = chars.next()?; |
| 369 | chars.next().is_none().then_some(first) |
| 370 | }); |
| 371 | let arg = node |
| 372 | .get_arguments() |
| 373 | .chain(root.get_arguments()) |
| 374 | .find(|arg| { |
| 375 | shown |
| 376 | .strip_prefix("--") |
| 377 | .is_some_and(|long| arg.get_long() == Some(long)) |
| 378 | || short.is_some_and(|short| arg.get_short() == Some(short)) |
| 379 | }); |
| 380 | |
| 381 | let Some(arg) = arg else { |
| 382 | return vec![shown.to_string()]; |
| 383 | }; |
| 384 | |
| 385 | let mut spellings = Vec::new(); |
| 386 | for long in arg.get_long_and_visible_aliases().unwrap_or_default() { |
| 387 | spellings.push(format!("--{long}")); |
| 388 | } |
| 389 | for short in arg.get_short_and_visible_aliases().unwrap_or_default() { |
| 390 | spellings.push(format!("-{short}")); |
| 391 | } |
| 392 | spellings |
| 393 | } |
| 394 | |
| 395 | fn attached_value(value: &OsStr, spelling: &str) -> Option<OsString> { |
| 396 | let prefixes = if spelling.starts_with("--") { |
no test coverage detected