Skip to main content

CommandSpec

Struct CommandSpec 

Source
pub struct CommandSpec {
Show 15 fields pub name: String, pub bin_name: Option<String>, pub version: Option<String>, pub about: String, pub long_about: Option<String>, pub aliases: Vec<String>, pub usage: Vec<String>, pub args: Vec<ArgSpec>, pub subcommands: Vec<CommandSpec>, pub examples: Vec<Example>, pub sections: Vec<Section>, pub heading_notes: Vec<HeadingNote>, pub subcommand_heading: Option<String>, pub subcommand_required: bool, pub hidden: bool,
}
Expand description

A command (or subcommand) and everything its documentation needs.

use rich_ext::cli_doc::{ArgSpec, CommandSpec};

let spec = CommandSpec::new("rich")
    .version("1.0.0")
    .about("Render files in the terminal")
    .arg(ArgSpec::flag("pager").help("Page the output"))
    .arg(ArgSpec::positional("resource"))
    .subcommand(CommandSpec::new("config").about("Show settings"));
assert_eq!(spec.usage_lines(), vec!["rich [OPTIONS] [RESOURCE] [COMMAND]".to_string()]);

Fields§

§name: String§bin_name: Option<String>

The executable name, when it differs from name.

§version: Option<String>§about: String§long_about: Option<String>§aliases: Vec<String>

Other names a subcommand answers to.

§usage: Vec<String>

Explicit usage lines; one is generated from the arguments when empty.

§args: Vec<ArgSpec>§subcommands: Vec<CommandSpec>§examples: Vec<Example>§sections: Vec<Section>§heading_notes: Vec<HeadingNote>§subcommand_heading: Option<String>

The title of the subcommand list; None means “Commands”.

§subcommand_required: bool

Whether a subcommand must be given (<COMMAND> rather than [COMMAND] in generated usage).

§hidden: bool

Hidden subcommands are left out of help, docs and completions.

Implementations§

Source§

impl CommandSpec

Source

pub fn new(name: impl Into<String>) -> Self

Source

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

Source

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

Source

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

Source

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

Source

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

Source

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

Add an explicit usage line (without the Usage: label).

Source

pub fn arg(self, arg: ArgSpec) -> Self

Source

pub fn args(self, args: impl IntoIterator<Item = ArgSpec>) -> Self

Source

pub fn subcommand(self, command: CommandSpec) -> Self

Source

pub fn example( self, command: impl Into<String>, description: impl Into<String>, ) -> Self

Source

pub fn section(self, title: impl Into<String>, body: impl Into<String>) -> Self

Source

pub fn heading_note( self, heading: impl Into<String>, text: impl Into<String>, ) -> Self

Add a note shown under the option group titled heading.

Source

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

Source

pub fn subcommand_required(self, required: bool) -> Self

Source

pub fn hidden(self, hidden: bool) -> Self

Source

pub fn display_name(&self) -> &str

The name the command is invoked by: bin_name, else name.

Source

pub fn visible_args(&self) -> impl Iterator<Item = &ArgSpec>

The arguments that are not hidden.

Source

pub fn visible_subcommands(&self) -> impl Iterator<Item = &CommandSpec>

The subcommands that are not hidden.

Source

pub fn find_subcommand(&self, name: &str) -> Option<&CommandSpec>

The subcommand called (or aliased) name.

Source

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

The visible option groups in first-seen order, each with its arguments. Positionals without a heading form a trailing “Arguments” group.

Source

pub fn note_for(&self, heading: &str) -> Option<&str>

The note for the group titled heading, if any.

Source

pub fn usage_lines(&self) -> Vec<String>

The usage lines, generated when none were given.

Source

pub fn usage_lines_as(&self, prefix: &str) -> Vec<String>

The usage lines with prefix (such as rich config) as the command. Explicit lines starting with this command’s name get the prefix substituted; generated lines are prefix [OPTIONS] <REQUIRED OPTIONS> [POSITIONALS] [COMMAND].

Source

pub fn switch_names(&self) -> Vec<String>

Every visible -s/--long spelling, for suggestions.

Source

pub fn subcommand_names(&self) -> Vec<String>

Every visible subcommand name and alias, for suggestions.

Source§

impl CommandSpec

Source

pub fn from_clap(cmd: &Command) -> CommandSpec

The spec of a clap command and its subcommands, including clap’s generated --help/--version flags and help subcommand.

Maps long, short and visible aliases, value names, possible values (with their help), value hints, defaults, environment variables, help headings, hidden, required and positional arguments; Count and Append actions (or more than one value) make an argument multiple. about, long_about, version, an overridden usage and the subcommand heading carry over; after_help (else after_long_help) becomes an untitled section.

Trait Implementations§

Source§

impl Clone for CommandSpec

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 CommandSpec

Source§

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

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

impl Default for CommandSpec

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Eq for CommandSpec

Source§

impl PartialEq for CommandSpec

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 StructuralPartialEq for CommandSpec

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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 = !

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.
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