Skip to main content

Catalog

Struct Catalog 

Source
pub struct Catalog<'a> { /* private fields */ }
Expand description

A validated collection of caller-supplied runtime command specs.

Building one validates; it does not assemble. The merged tree help and completion navigate costs a KDL round trip of the whole host spec, and dispatching a plugin command needs none of it — so it is built when something asks for it, and a host that only ever runs plugins never pays. See app.

Implementations§

Source§

impl<'a> Catalog<'a>

Source

pub fn builder(host: SpecView<'a>) -> Builder<'a>

Begin a catalog over a derive-generated Cli::app().

Source

pub fn app(&self) -> Result<App<'_>, &Error>

Help and completion over the whole tree, static commands and runtime ones alike.

The merged tree is assembled here, on the first call, and kept. Building it is a KDL round trip of the host spec — cheap next to rendering a page, and not something parse_external should ever pay for, which is why it waits until somebody asks.

The error is a disagreement between the derived tables and the spec model that read them, which Builder::build cannot see because it has not lowered the host yet.

Source

pub fn is_assembled(&self) -> bool

Whether the merged tree has been assembled yet.

app builds it once and keeps it, so this answers whether the next call is the expensive one. A catalog that is only ever dispatched through never assembles.

Source

pub fn parse_external( &self, parent: &str, argv: &[OsString], ) -> Result<Option<Outcome>, Error>

Parse the argv an external-subcommand variant captured.

parent is the static command path the catch-all sits on, with the empty string meaning the root. The first token is the runtime command’s name, by any spelling it answers to.

Two of the outcomes here are the caller’s to handle rather than errors:

  • Ok(None) — no catalogued command answers to that name. Whatever the host did with unrecognized words before it had a catalog, it should still do.
  • Err(Error::NonUtf8) — a token the portable spec model cannot represent, because it parses Strings and this one is not one. The derive handed over OsStrings, which lose nothing, so the argv is still intact: dispatch it the same way as Ok(None) rather than failing a command whose argument happens to be an unusual path.

Defaults and environment fallbacks are applied by the plugin’s own spec, and --help and --version come back as Outcomes rather than as errors.

Trait Implementations§

Source§

impl<'a> Debug for Catalog<'a>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !Freeze for Catalog<'a>

§

impl<'a> RefUnwindSafe for Catalog<'a>

§

impl<'a> Send for Catalog<'a>

§

impl<'a> Sync for Catalog<'a>

§

impl<'a> Unpin for Catalog<'a>

§

impl<'a> UnsafeUnpin for Catalog<'a>

§

impl<'a> UnwindSafe for Catalog<'a>

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.