Skip to main content

ParseOutput

Struct ParseOutput 

Source
#[non_exhaustive]
pub struct ParseOutput {
Show 15 fields pub cmd: SpecCommand, pub cmds: Vec<SpecCommand>, pub args: IndexMap<Arc<SpecArg>, ParseValue>, pub flags: IndexMap<Arc<SpecFlag>, ParseValue>, pub tokens: Vec<TokenBinding>, pub flag_origins: IndexMap<Arc<SpecFlag>, Vec<ValueOrigin>>, pub arg_origins: IndexMap<Arc<SpecArg>, Vec<ValueOrigin>>, pub overridden_flags: BTreeMap<String, String>, pub available_flags: BTreeMap<String, Arc<SpecFlag>>, pub flag_awaiting_value: Vec<Arc<SpecFlag>>, pub errors: Vec<UsageErr>, pub warnings: Vec<Warning>, pub next_arg: Option<Arc<SpecArg>>, pub double_dash_seen: bool, pub external: Option<Vec<String>>,
}

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.
§cmd: SpecCommand§cmds: Vec<SpecCommand>§args: IndexMap<Arc<SpecArg>, ParseValue>§flags: IndexMap<Arc<SpecFlag>, ParseValue>§tokens: Vec<TokenBinding>

What each word of the command line became, in argv order, one entry per word.

The token half of provenance; ParseOutput::flag_origins and ParseOutput::arg_origins are the other half. A table keyed by token cannot show a value that came from nowhere in argv, and a table keyed by declaration cannot show a token that bound to nothing, so both exist.

§flag_origins: IndexMap<Arc<SpecFlag>, Vec<ValueOrigin>>

Where a flag’s value came from when it did not come from argv, in the order the fallbacks fired. Keyed as ParseOutput::flags is.

A list rather than one origin: repeated bare occurrences of a var flag each take a default_missing value, so one flag can have several.

§arg_origins: IndexMap<Arc<SpecArg>, Vec<ValueOrigin>>

Where an argument’s value came from when it did not come from argv. Keyed as ParseOutput::args is.

§overridden_flags: BTreeMap<String, String>

Flags a later occurrence removed, and the flag that removed them.

The overriding name is the half a caller needs: the fallback phase silently declines to fill an overridden flag, so “why is --quiet unset when its default says otherwise” has no answer without it.

§available_flags: BTreeMap<String, Arc<SpecFlag>>

Every flag the parser recognizes at this point, keyed by each of its aliases (--long, -s, negations).

This includes flags that only remain recognized because they may appear before a mounted command — see ParseOutput::completion_flags for the set a completion should offer.

§flag_awaiting_value: Vec<Arc<SpecFlag>>§errors: Vec<UsageErr>§warnings: Vec<Warning>

Deprecated declarations this command line used, for the caller to render when its logging is up. Empty from parse_partial: a half-typed line being completed has not used anything yet.

§next_arg: Option<Arc<SpecArg>>

The positional argument the next word would have filled, i.e. where the parser’s cursor stopped. None once every argument is satisfied.

Completions need exactly this: the parser already accounts for var_max, for restart_token rewinds, and for the jump an explicit -- performs onto a double_dash="required" argument, so re-deriving it from args would disagree.

§double_dash_seen: bool

Whether an explicit -- was consumed as a separator.

A -- that double_dash="preserve" keeps as a value does not count: it is a value of the variadic argument collecting it, not a separator, so it does not unlock a double_dash="required" argument.

§external: Option<Vec<String>>

Remaining argv captured when an unmatched word was forwarded as an external subcommand: the command name first, then every token after it.

Absent when no external command was selected. See SpecCommand::external_subcommand.

Implementations§

Source§

impl ParseOutput

Source

pub fn completion_flags(&self) -> BTreeMap<String, Arc<SpecFlag>>

The flags a completion should offer for the parsed command.

Usually every recognized flag, i.e. ParseOutput::available_flags. Once a mounted command has been reached, though, the commands above it belong to the mounting CLI and their flags are not accepted there — mise, for example, forwards everything after a task name to the task itself — so only the flags declared from the mount boundary down are offered. Those globals stay in available_flags because they may legitimately appear before the mounted command.

Source§

impl ParseOutput

Source

pub fn as_env(&self) -> BTreeMap<String, String>

Trait Implementations§

Source§

impl Debug for ParseOutput

Source§

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

Formats the value using the given formatter. 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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. 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.