Skip to main content

SubcommandSet

Struct SubcommandSet 

Source
pub struct SubcommandSet<Ctx> { /* private fields */ }

Implementations§

Source§

impl<Ctx: 'static> SubcommandSet<Ctx>

Source

pub fn toggle<F>( self, name: &'static str, help: &'static str, handler: F, ) -> Self
where F: FnMut(&mut Ctx, Option<bool>) -> Result<()> + 'static,

Parses on|off|true|false|1|0; a bare invocation passes None.

Source

pub fn choice<F>( self, name: &'static str, help: &'static str, choices: &[&'static str], handler: F, ) -> Self
where F: FnMut(&mut Ctx, Option<&str>) -> Result<()> + 'static,

The handler receives the raw value string, unvalidated against choices.

Source

pub fn custom<F>( self, name: &'static str, help: &'static str, arg_choices: &[&[&'static str]], value_choices: &[(&'static str, &[&'static str])], handler: F, ) -> Self
where F: FnMut(&mut Ctx, &[&str], &mut ConsoleWriter) -> Result<()> + 'static,

arg_choices[i] completes the i-th arg after the subcommand name.

Source

pub fn with_long_help(self, long: &'static str) -> Self

The subcommand table is appended either way.

Source

pub fn on_bare<F>(self, handler: F) -> Self
where F: FnMut(&mut Ctx) -> Result<()> + 'static,

A bare command name runs handler instead of a usage error.

Trait Implementations§

Source§

impl<Ctx: 'static> Command<Ctx> for SubcommandSet<Ctx>

Source§

fn name(&self) -> &str

Source§

fn help(&self) -> &str

Source§

fn long_help(&self) -> String

\n breaks paint as separate scrollback entries.
Source§

fn arg_choices(&self, arg_index: usize) -> &[&'static str]

Source§

fn arg_choices_ctx<'a>( &'a self, arg_index: usize, prior: &[&str], ) -> &'a [&'static str]

prior is the arg tokens before the cursor.
Source§

fn arg_value_choices_ctx<'a>( &'a self, _arg_index: usize, key: &str, prior: &[&str], ) -> &'a [&'static str]

Source§

fn run( &mut self, args: &[&str], ctx: &mut Ctx, out: &mut ConsoleWriter, ) -> Result<()>

Recoverable issues go to out.error(..); unrecoverable ones return Err.
Source§

fn arg_value_choices(&self, arg_index: usize, key: &str) -> &[&'static str]

key carries no trailing =; empty means free-form.

Auto Trait Implementations§

§

impl<Ctx> !Freeze for SubcommandSet<Ctx>

§

impl<Ctx> !RefUnwindSafe for SubcommandSet<Ctx>

§

impl<Ctx> !Send for SubcommandSet<Ctx>

§

impl<Ctx> !Sync for SubcommandSet<Ctx>

§

impl<Ctx> Unpin for SubcommandSet<Ctx>

§

impl<Ctx> UnsafeUnpin for SubcommandSet<Ctx>

§

impl<Ctx> !UnwindSafe for SubcommandSet<Ctx>

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