Skip to main content

Surface

Struct Surface 

Source
#[non_exhaustive]
pub struct Surface { pub binary: String, pub mount: String, pub about: String, pub version: Option<String>, pub arguments: Vec<SurfaceArgument>, pub inherited_arguments: Vec<SurfaceArgument>, pub commands: Vec<SurfaceCommand>, pub usage_kdl: String, pub mount_line: String, pub notes: BTreeMap<String, String>, }
Available on crate feature surface-model only.
Expand description

What a user sees of one Clap command tree.

Build it with Surface::new or Surface::from_command. It is plain data: a test compares a render of it with a committed file, and a template reads its fields. A field can join it in a minor release.

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.
§binary: String

Executable name declared by the root Clap command.

§mount: String

The mise task name that runs the CLI.

§about: String

Root command description.

§version: Option<String>

Root package version, when Clap declares one.

§arguments: Vec<SurfaceArgument>

Arguments and flags declared directly on the root, in Clap order.

§inherited_arguments: Vec<SurfaceArgument>

Ancestor global arguments, always empty for the root.

§commands: Vec<SurfaceCommand>

Root subcommands in Clap declaration order, including hidden commands.

§usage_kdl: String

Usage KDL for the mise task name.

§mount_line: String

The exact #USAGE mount line for the mise task.

§notes: BTreeMap<String, String>

Prose the CLI adds by name, for its documentation templates.

Implementations§

Source§

impl Surface

Source

pub fn new<C: CommandFactory>(mount: impl Into<String>) -> Self

The surface of the Clap parser type C.

mount is the mise task name that runs the CLI, such as toy in mise run toy status. See Self::from_command.

Source

pub fn from_command(command: Command, mount: impl Into<String>) -> Self

The surface of a Clap command tree.

mount is the mise task name that runs the CLI. The Usage KDL and the #USAGE mount line use it. Hidden commands are listed with hidden set. The Usage KDL holds the -h/--help flag and help subcommand ctl-core declares on every command, as apply_defaults does for parsing. The lists of arguments and commands leave them out.

Source

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

Add the CLI’s own prose under name, for one template section or reader. A template reads it as surface.notes.<name>. A later note of the same name replaces an earlier one.

Source

pub fn long_options_without_short(&self) -> Vec<(String, String)>

Long flags that have no short, as (command path, long name).

The root path is empty. Inherited globals are not repeated on children. Hidden flags are included so a long-only option cannot hide from the check. FormatLong and ColorLong leave --format / --color without shorts on purpose; pass those names to Self::require_shorts.

Source

pub fn require_shorts<'a>( &self, allow: impl IntoIterator<Item = &'a str>, ) -> Result<(), String>

Fail when a long option has no visible short, except tokens in allow.

A root allowance is the displayed long option (--format). A nested allowance includes its command path (status --archived). ctl-core’s shared flags that leave a letter free for the CLI on purpose (--format for -f/--file, --color for -c) belong there.

§Errors

Returns a message that lists every long option without a short, outside allow.

Trait Implementations§

Source§

impl Clone for Surface

Source§

fn clone(&self) -> Self

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 Surface

Source§

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

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

impl Eq for Surface

Source§

impl PartialEq for Surface

Source§

fn eq(&self, other: &Self) -> 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 Surface

Available on crate feature surface-serde only.
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 Surface

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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, O> Matches<O> for T
where T: PartialEq<O>,

Source§

fn validate_matches(&self, other: &O) -> bool

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.