Skip to main content

Ctx

Struct Ctx 

Source
pub struct Ctx {
    pub app_name: String,
    pub command: String,
    pub globals: Globals,
    /* private fields */
}
Expand description

Everything a command body needs. Borrow-friendly: methods take &self.

Fields§

§app_name: String§command: String§globals: Globals

Implementations§

Source§

impl Ctx

Source

pub fn arg(&self, name: &str) -> Result<&str>

A required positional argument.

Source

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

An optional positional argument.

Source

pub fn args(&self, name: &str) -> Vec<String>

All values of a variadic positional.

Source

pub fn flag(&self, long: &str) -> bool

Whether a boolean flag was set.

Source

pub fn value(&self, long: &str) -> Option<&str>

A value flag, if present (or its default).

Source

pub fn value_as<T: FromStr>(&self, long: &str) -> Result<Option<T>>

A value flag parsed into any FromStr type.

Source

pub fn is_dry_run(&self) -> bool

Source

pub fn is_json(&self) -> bool

Source

pub fn info<S: AsRef<str>>(&self, msg: S)

Source

pub fn success<S: AsRef<str>>(&self, msg: S)

Source

pub fn warn<S: AsRef<str>>(&self, msg: S)

Source

pub fn debug<S: AsRef<str>>(&self, level: u8, msg: S)

Source

pub fn ok<S: AsRef<str>>(&self, msg: S) -> Result<()>

Standard success return for a command that finished a unit of work.

Source

pub fn action<S: AsRef<str>>(&self, msg: S)

Print a line only when not in dry-run, prefixing with the theme’s dry-run marker when it is, so a dry run narrates what it would do.

Source

pub fn require_root(&self) -> Result<()>

Enforce a root requirement using the resolved --sudo global.

Source

pub fn require_confirmation(&self, confirmed: bool) -> Result<()>

Enforce destructive confirmation. confirmed is typically ctx.flag(DEFAULT_CONFIRM_FLAG) (or your themed confirm-flag name).

Auto Trait Implementations§

§

impl Forget for Ctx

§

impl Freeze for Ctx

§

impl Move for Ctx

§

impl RefUnwindSafe for Ctx

§

impl Send for Ctx

§

impl Sync for Ctx

§

impl Unpin for Ctx

§

impl UnsafeUnpin for Ctx

§

impl UnwindSafe for 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 = !

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.