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

Function short_cluster_value

atomic-cli/src/agent_error.rs:441–486  ·  view source on GitHub ↗
(
    root: &clap::Command,
    key: &str,
    argv: &[OsString],
    index: usize,
    spellings: &[String],
)

Source from the content-addressed store, hash-verified

439}
440
441fn short_cluster_value(
442 root: &clap::Command,
443 key: &str,
444 argv: &[OsString],
445 index: usize,
446 spellings: &[String],
447) -> Option<Option<OsString>> {
448 let token = argv[index].to_str()?;
449 let cluster = token.strip_prefix('-')?;
450 if cluster.is_empty() || cluster.starts_with('-') {
451 return None;
452 }
453
454 let target = spellings.iter().filter_map(|spelling| {
455 let short = spelling.strip_prefix('-')?;
456 let mut chars = short.chars();
457 let value = chars.next()?;
458 chars.next().is_none().then_some(value)
459 });
460 let target = target.collect::<Vec<_>>();
461 let node = walk_to(root, key);
462
463 for (offset, short) in cluster.char_indices() {
464 let arg = node
465 .get_arguments()
466 .chain(root.get_arguments())
467 .find(|arg| {
468 arg.get_short() == Some(short)
469 || arg
470 .get_all_short_aliases()
471 .is_some_and(|aliases| aliases.contains(&short))
472 })?;
473 let suffix = &cluster[offset + short.len_utf8()..];
474 if target.contains(&short) {
475 return Some(match suffix.strip_prefix('=') {
476 Some(value) => Some(OsString::from(value)),
477 None if suffix.is_empty() => argv.get(index + 1).cloned(),
478 None => Some(OsString::from(suffix)),
479 });
480 }
481 if arg.get_action().takes_values() {
482 return None;
483 }
484 }
485 None
486}
487
488fn raw_option_value(
489 root: &clap::Command,

Callers 1

raw_option_valueFunction · 0.85

Calls 7

walk_toFunction · 0.85
is_noneMethod · 0.80
getMethod · 0.65
is_emptyMethod · 0.45
iterMethod · 0.45
nextMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected