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: boolThis 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
impl ArgSpec
pub fn flag(long: impl Into<String>) -> Self
pub fn option(long: impl Into<String>, value_name: impl Into<String>) -> Self
pub fn option_i64( long: impl Into<String>, value_name: impl Into<String>, ) -> Self
pub fn option_f64( long: impl Into<String>, value_name: impl Into<String>, ) -> Self
pub fn option_json( long: impl Into<String>, value_name: impl Into<String>, ) -> Self
pub fn option_enum<I, S>(long: impl Into<String>, values: I) -> Self
Sourcepub fn uuid(self) -> Self
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.
Sourcepub fn range(self, minimum: i64, maximum: i64) -> Self
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.
pub fn positional( argument_id: impl Into<String>, index: usize, value_name: impl Into<String>, ) -> Self
pub fn positional_json( argument_id: impl Into<String>, index: usize, value_name: impl Into<String>, ) -> Self
pub fn positional_enum<I, S>( argument_id: impl Into<String>, index: usize, value_name: impl Into<String>, values: I, ) -> Self
pub fn value_name(self, value_name: impl Into<String>) -> Self
pub fn default(self, value: impl Into<String>) -> Self
pub fn default_i64(self, value: i64) -> Self
pub fn default_f64(self, value: f64) -> Self
pub fn repeatable(self) -> Self
Sourcepub fn sensitive(self) -> Self
pub fn sensitive(self) -> Self
Mark this argument’s value as one that must never be echoed back.
Sourcepub fn sources(self, sources: SourceSet) -> Self
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.
pub fn about(self, about: impl Into<String>) -> Self
Sourcepub fn rendered_about(&self) -> Option<String>
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: a single flag’s syntax is otherwise repeated across
every row of a generated reference that mentions it — dozens, for a
widely-used one — each a place to forget when a source is added.