Skip to main content

ArgSpec

Struct ArgSpec 

Source
pub struct ArgSpec {
    pub argument_id: String,
    pub syntax: ArgSyntax,
    pub value_type: ArgValueType,
    pub value_name: Option<String>,
    pub enum_values: Vec<String>,
    pub range: Option<[i64; 2]>,
    pub default: Option<CliValue>,
    pub repeatable: bool,
    pub sensitive: bool,
    pub sources: Option<SourceSet>,
    pub about: Option<String>,
}
Expand description

One command-local application argument.

Fields§

§argument_id: String§syntax: ArgSyntax§value_type: ArgValueType§value_name: Option<String>§enum_values: Vec<String>§range: Option<[i64; 2]>

Inclusive bounds for an I64 argument.

Lets a registry say 1..=1000 without a host-supplied parser, so a count that must fit an i32, a usize, or a NonZero is rejected at exit 2 with the other usage errors rather than checked again inside the handler — where the only honest report left is a domain failure.

§default: Option<CliValue>§repeatable: bool§sensitive: bool

This argument’s value must never be echoed back.

The core only consumes the bit: it suppresses help defaults, keeps the value out of rendered templates, and rejects a serializable default. Which arguments deserve it is a host convention — crate::cli_afdata derives it from AFDATA’s _secret suffix.

§sources: Option<SourceSet>

The sources this argument accepts beside a literal value.

Declared rather than assumed: a source turns an argument into a reader of files and environment variables, which is right for a credential and wrong for most everything else. The core validates that a value names only a scheme in this set, and renders the syntax into help so no host repeats it in an about string. Reading happens in the host, when it chooses — see crate::value_source.

§about: Option<String>

Implementations§

Source§

impl ArgSpec

Source

pub fn flag(long: impl Into<String>) -> Self

Source

pub fn option(long: impl Into<String>, value_name: impl Into<String>) -> Self

Source

pub fn option_i64( long: impl Into<String>, value_name: impl Into<String>, ) -> Self

Source

pub fn option_f64( long: impl Into<String>, value_name: impl Into<String>, ) -> Self

Source

pub fn option_json( long: impl Into<String>, value_name: impl Into<String>, ) -> Self

Source

pub fn option_enum<I, S>(long: impl Into<String>, values: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Source

pub fn uuid(self) -> Self

Read this argument as a canonical RFC 4122 UUID.

The resolved value is still a CliValue::String; what changes is that a malformed one is rejected as a usage error before the command runs.

Source

pub fn range(self, minimum: i64, maximum: i64) -> Self

Constrain an I64 argument to an inclusive range.

Use it for a count that must fit a narrower integer than i64 — the check then reports as a usage error, beside the other argument failures, rather than as a domain failure from inside the handler.

Source

pub fn positional( argument_id: impl Into<String>, index: usize, value_name: impl Into<String>, ) -> Self

Source

pub fn positional_json( argument_id: impl Into<String>, index: usize, value_name: impl Into<String>, ) -> Self

Source

pub fn positional_enum<I, S>( argument_id: impl Into<String>, index: usize, value_name: impl Into<String>, values: I, ) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Source

pub fn value_name(self, value_name: impl Into<String>) -> Self

Source

pub fn default(self, value: impl Into<String>) -> Self

Source

pub fn default_i64(self, value: i64) -> Self

Source

pub fn default_f64(self, value: f64) -> Self

Source

pub fn repeatable(self) -> Self

Source

pub fn sensitive(self) -> Self

Mark this argument’s value as one that must never be echoed back.

Source

pub fn sources(self, sources: SourceSet) -> Self

Accept the value indirectly, from any source in sources.

The help text follows from the set, so about should say what the value is and leave the syntax to this. Reading is the host’s, at the moment it chooses: crate::cli_spec::SourceSet::parse on the resolved string, then read or read_secret.

Source

pub fn about(self, about: impl Into<String>) -> Self

Source

pub fn rendered_about(&self) -> Option<String>

What a reader is told about this argument: what the value means, plus how it may be sourced.

Hosts declare those separately — about says what the value is, the source set says where it may come from — and every rendering path joins them here. That is the whole reason the set is declared rather than written into prose: one afhttp flag’s syntax was repeated across nine rows of its generated reference, and one afpsql flag’s across forty-eight, each a place to forget when a source is added.

Trait Implementations§

Source§

impl Clone for ArgSpec

Source§

fn clone(&self) -> ArgSpec

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 ArgSpec

Source§

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

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

impl<'de> Deserialize<'de> for ArgSpec

Source§

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

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

impl PartialEq for ArgSpec

Source§

fn eq(&self, other: &ArgSpec) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for ArgSpec

Source§

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

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for ArgSpec

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> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more