#[non_exhaustive]pub struct ToolArgs {
pub positional: Vec<Value>,
pub named: BTreeMap<String, Value>,
pub flags: HashSet<String>,
}Expand description
Parsed arguments ready for tool execution.
Fields (Non-exhaustive)§
This struct is marked as non-exhaustive
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.positional: Vec<Value>Positional arguments in order.
named: BTreeMap<String, Value>Named arguments by key.
flags: HashSet<String>Boolean flags (e.g., -l, –force).
Implementations§
Source§impl ToolArgs
impl ToolArgs
Sourcepub fn get_positional(&self, index: usize) -> Option<&Value>
pub fn get_positional(&self, index: usize) -> Option<&Value>
Get a positional argument by index.
Sourcepub fn get(&self, name: &str, positional_index: usize) -> Option<&Value>
pub fn get(&self, name: &str, positional_index: usize) -> Option<&Value>
Get a named argument or positional fallback.
Useful for tools that accept both cat file.txt and cat path=file.txt.
Sourcepub fn get_string(&self, name: &str, positional_index: usize) -> Option<String>
pub fn get_string(&self, name: &str, positional_index: usize) -> Option<String>
Get a string value from args.
Sourcepub fn get_bool(&self, name: &str, positional_index: usize) -> Option<bool>
pub fn get_bool(&self, name: &str, positional_index: usize) -> Option<bool>
Get a boolean value from args.
Sourcepub fn has_flag(&self, name: &str) -> bool
pub fn has_flag(&self, name: &str) -> bool
Check if a flag is set (in flags set, or named bool).
Sourcepub fn flagify_bool_named(&mut self)
pub fn flagify_bool_named(&mut self)
Move bool entries from named into the appropriate set so a downstream
clap parser (with #[arg(...)] field: bool) accepts them.
Tests routinely seed args.named.insert(K, Value::Bool(true)) for the
schema-pre-clap path; to_argv() would emit those as --K=true, which
clap rejects for bool fields. Promote to:
Bool(true)→ presence inflags(clap sees--K).Bool(false)→ dropped (clap treats absent flag and explicit false the same; preserving it would only resurface as--K=falseand break the same parser).
Idempotent. Non-bool named entries are left alone.
Sourcepub fn to_argv(&self) -> Vec<String>
pub fn to_argv(&self) -> Vec<String>
Reconstruct a clap-friendly argv vector from already-parsed ToolArgs.
kaish has already done shell parsing (variables expanded, globs expanded,
$(...) substituted, schema-driven flag/value splitting). to_argv
rebuilds a flat token stream suitable for Parser::parse_from(std::iter::once("<tool>").chain(args.to_argv())).
Layout: flags first (as --<name>), then named values (as
--<name>=<value>), then positionals — separated from earlier sections
by -- so trailing-passthrough builtins still see them as positionals
even if a value happens to begin with -.
See docs/clap-migration.md for the full recipe.