MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / option_spellings

Function option_spellings

atomic-cli/src/agent_error.rs:359–393  ·  view source on GitHub ↗
(root: &clap::Command, key: &str, display: &str)

Source from the content-addressed store, hash-verified

357}
358
359fn 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
395fn attached_value(value: &OsStr, spelling: &str) -> Option<OsString> {
396 let prefixes = if spelling.starts_with("--") {

Callers 1

raw_option_valueFunction · 0.85

Calls 4

walk_toFunction · 0.85
is_noneMethod · 0.80
nextMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected