Skip to main content

ParamSchema

Struct ParamSchema 

Source
#[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
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§name: String

Parameter name.

§param_type: String

Type hint (string, int, bool, array, object, any).

§required: bool

Whether this parameter is required.

§default: Option<Value>

Default value if not required.

§description: String

Description for help text.

§aliases: Vec<String>

Alternative names/flags for this parameter (e.g., “-r”, “-R” for “recursive”).

§consumes: usize

Number 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: bool

True 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

Source

pub fn required( name: impl Into<String>, param_type: impl Into<String>, description: impl Into<String>, ) -> ParamSchema

Create a required parameter.

Source

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.

Source

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.

Source

pub fn with_description(self, description: impl Into<String>) -> ParamSchema

Set the human-readable description.

Source

pub fn with_required(self, required: bool) -> ParamSchema

Set whether the parameter is required.

Source

pub fn with_default(self, default: Option<Value>) -> ParamSchema

Set the default value (used when the parameter is omitted).

Source

pub fn with_positional(self, positional: bool) -> ParamSchema

Set the positional flag from a computed boolean (the parameterless positional sets it unconditionally to true).

Source

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.

Source

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.

Source

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.

Source

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

Source§

fn clone(&self) -> ParamSchema

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ParamSchema

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for ParamSchema

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<ParamSchema, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for ParamSchema

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.