#[non_exhaustive]pub struct ParamSchema {
pub name: String,
pub param_type: String,
pub required: bool,
pub default: Option<Value>,
pub description: String,
pub aliases: Vec<String>,
pub consumes: usize,
pub positional: bool,
}Expand description
Schema for a tool parameter.
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.name: StringParameter name.
param_type: StringType hint (string, int, bool, array, object, any).
required: boolWhether this parameter is required.
default: Option<Value>Default value if not required.
description: StringDescription for help text.
aliases: Vec<String>Alternative names/flags for this parameter (e.g., “-r”, “-R” for “recursive”).
consumes: usizeNumber of positional tokens this non-bool flag consumes per occurrence.
Default 1 (standard --flag value). Set to 2 for --flag NAME VALUE
patterns such as jq’s --arg / --argjson. When consumes > 1, the
kernel collects each occurrence as an inner array and accumulates
repeated occurrences under the same named key — the tool sees a
Value::Json(Array(Array(...))) listing every (N-tuple) occurrence.
positional: boolTrue for positional arguments (cat foo.txt), false for flags
(grep --ignore-case). The validator matches positional params
against args.positional by their order among positionals only,
independent of where they sit in the clap struct. Default false so
hand-built ParamSchema::required(...) constructors keep flag
semantics; clap-reflected positionals set it via
arg.get_index().is_some().
Implementations§
Source§impl ParamSchema
impl ParamSchema
Sourcepub fn required(
name: impl Into<String>,
param_type: impl Into<String>,
description: impl Into<String>,
) -> ParamSchema
pub fn required( name: impl Into<String>, param_type: impl Into<String>, description: impl Into<String>, ) -> ParamSchema
Create a required parameter.
Sourcepub fn optional(
name: impl Into<String>,
param_type: impl Into<String>,
default: Value,
description: impl Into<String>,
) -> ParamSchema
pub fn optional( name: impl Into<String>, param_type: impl Into<String>, default: Value, description: impl Into<String>, ) -> ParamSchema
Create an optional parameter with a default value.
Sourcepub fn new(
name: impl Into<String>,
param_type: impl Into<String>,
) -> ParamSchema
pub fn new( name: impl Into<String>, param_type: impl Into<String>, ) -> ParamSchema
Create a minimal parameter (not required, no default, empty
description, consumes 1, flag — not positional). Chain the with_*
setters to fill in fields. Use this when each field is computed
independently (e.g. reflected from clap) rather than fitting the
required/optional shortcuts. Keeps construction working across the
#[non_exhaustive] boundary.
Sourcepub fn with_description(self, description: impl Into<String>) -> ParamSchema
pub fn with_description(self, description: impl Into<String>) -> ParamSchema
Set the human-readable description.
Sourcepub fn with_required(self, required: bool) -> ParamSchema
pub fn with_required(self, required: bool) -> ParamSchema
Set whether the parameter is required.
Sourcepub fn with_default(self, default: Option<Value>) -> ParamSchema
pub fn with_default(self, default: Option<Value>) -> ParamSchema
Set the default value (used when the parameter is omitted).
Sourcepub fn with_positional(self, positional: bool) -> ParamSchema
pub fn with_positional(self, positional: bool) -> ParamSchema
Set the positional flag from a computed boolean (the parameterless
positional sets it unconditionally to true).
Sourcepub fn positional(self) -> ParamSchema
pub fn positional(self) -> ParamSchema
Mark this parameter as positional (matched by argv order rather than
by name). Used by params_from_clap for clap args with an assigned
index, and by hand-written schemas for positional parameters like
jq’s filter.
Sourcepub fn with_aliases(
self,
aliases: impl IntoIterator<Item = impl Into<String>>,
) -> ParamSchema
pub fn with_aliases( self, aliases: impl IntoIterator<Item = impl Into<String>>, ) -> ParamSchema
Add alternative names/flags for this parameter.
Aliases are used for short flags like -r, -R that map to recursive.
Sourcepub fn consumes(self, n: usize) -> ParamSchema
pub fn consumes(self, n: usize) -> ParamSchema
Declare how many positional tokens this non-bool flag consumes per
occurrence (--flag v1 v2 ...). Default is 1. Panics on 0 — a flag
that consumes nothing is a bool flag, not a schema-typed param.
Sourcepub fn matches_flag(&self, flag: &str) -> bool
pub fn matches_flag(&self, flag: &str) -> bool
Check if a flag name matches this parameter or any of its aliases.
Trait Implementations§
Source§impl Clone for ParamSchema
impl Clone for ParamSchema
Source§fn clone(&self) -> ParamSchema
fn clone(&self) -> ParamSchema
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more