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: GlobalsImplementations§
Source§impl Ctx
impl Ctx
Sourcepub fn value_as<T: FromStr>(&self, long: &str) -> Result<Option<T>>
pub fn value_as<T: FromStr>(&self, long: &str) -> Result<Option<T>>
A value flag parsed into any FromStr type.
pub fn is_dry_run(&self) -> bool
pub fn is_json(&self) -> bool
pub fn info<S: AsRef<str>>(&self, msg: S)
pub fn success<S: AsRef<str>>(&self, msg: S)
pub fn warn<S: AsRef<str>>(&self, msg: S)
pub fn debug<S: AsRef<str>>(&self, level: u8, msg: S)
Sourcepub fn ok<S: AsRef<str>>(&self, msg: S) -> Result<()>
pub fn ok<S: AsRef<str>>(&self, msg: S) -> Result<()>
Standard success return for a command that finished a unit of work.
Sourcepub fn action<S: AsRef<str>>(&self, msg: S)
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.
Sourcepub fn require_root(&self) -> Result<()>
pub fn require_root(&self) -> Result<()>
Enforce a root requirement using the resolved --sudo global.
Sourcepub fn require_confirmation(&self, confirmed: bool) -> Result<()>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more