#[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 repeatable: bool,
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.
repeatable: boolTrue when this flag may appear more than once and each occurrence
should be kept (clap’s ArgAction::Append, i.e. a Vec<_> value flag
like sed’s -e). When set, the kernel accumulates every occurrence
under the same named key as a Value::Json(Array(...)) instead of
letting the last write win — the “no silent drop” contract for repeated
flags. Orthogonal to consumes: consumes is values-per-occurrence,
repeatable is occurrences-per-invocation.
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 with_repeatable(self, repeatable: bool) -> ParamSchema
pub fn with_repeatable(self, repeatable: bool) -> ParamSchema
Mark this flag as repeatable: each occurrence is accumulated rather than
overwritten (see repeatable). Set from a computed
boolean so clap reflection can pass ArgAction::Append directly.
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 moreSource§impl Debug for ParamSchema
impl Debug for ParamSchema
Source§impl<'de> Deserialize<'de> for ParamSchema
impl<'de> Deserialize<'de> for ParamSchema
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<ParamSchema, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<ParamSchema, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Source§impl Serialize for ParamSchema
impl Serialize for ParamSchema
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Auto Trait Implementations§
impl Freeze for ParamSchema
impl RefUnwindSafe for ParamSchema
impl Send for ParamSchema
impl Sync for ParamSchema
impl Unpin for ParamSchema
impl UnsafeUnpin for ParamSchema
impl UnwindSafe for ParamSchema
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
impl<T> OrderedSeq<'_, T> for Twhere
T: Clone,
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
impl<'p, T> Seq<'p, T> for Twhere
T: Clone,
Source§impl<T, S> SpanWrap<S> for Twhere
S: WrappingSpan<T>,
impl<T, S> SpanWrap<S> for Twhere
S: WrappingSpan<T>,
Source§fn with_span(self, span: S) -> <S as WrappingSpan<Self>>::Spanned
fn with_span(self, span: S) -> <S as WrappingSpan<Self>>::Spanned
WrappingSpan::make_wrapped to wrap an AST node in a span.