Skip to main content

Ctx

Struct Ctx 

Source
pub struct Ctx<'a> {
    pub platform: &'a dyn Platform,
    pub out: &'a mut dyn Write,
    pub err: &'a mut dyn Write,
    pub input: &'a mut dyn BufRead,
    pub globals: Globals,
    /* private fields */
}
Expand description

A run: the platform, the outputs and the configuration, read only when a command needs it.

Fields§

§platform: &'a dyn Platform§out: &'a mut dyn Write§err: &'a mut dyn Write§input: &'a mut dyn BufRead§globals: Globals

Implementations§

Source§

impl<'a> Ctx<'a>

Source

pub fn new( platform: &'a dyn Platform, out: &'a mut dyn Write, err: &'a mut dyn Write, input: &'a mut dyn BufRead, globals: Globals, ) -> Ctx<'a>

Source

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

Source

pub fn config_path(&self) -> Result<PathBuf, CliError>

The path of config.yml.

Source

pub fn select_profile(&mut self, name: Option<String>)

Makes name the profile the next calls use, as --profile would.

Source

pub fn load_config(&self) -> Result<ConfigFile, CliError>

The profiles file (empty if it does not exist yet).

Source

pub fn save_config(&self, file: &ConfigFile) -> Result<(), CliError>

Source

pub fn settings(&mut self) -> Result<&Effective, CliError>

The effective configuration: variables, chosen profile and built-in values.

Source

pub fn json_chosen(&mut self) -> bool

true when the person chose json (on the command line, in the environment or in the profile), and not when it is only the built-in value: only then does the error come out as the server’s ErrorResponse.

Source

pub fn format(&mut self) -> Result<Format, CliError>

Source

pub fn api_client(&mut self) -> Result<Client, CliError>

The client API client (with the profile’s token).

Source

pub fn ops_client(&mut self, attempts: Option<u32>) -> Result<Client, CliError>

The operations API client: no token. attempts overrides the profile’s max-attempts.

Source

pub fn say(&mut self, text: &str) -> Result<(), CliError>

Writes a line to standard output.

Source

pub fn confirm(&mut self, question: &str) -> Result<bool, CliError>

Asks [y/N] on a terminal. Off a terminal it does not ask: the caller requires --yes.

Source

pub fn require_confirmation( &mut self, yes: bool, question: &str, ) -> Result<(), CliError>

Asks for confirmation of an action that deletes: --yes is enough; without it, it asks on a terminal and refuses (code 2) off one.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for Ctx<'a>

§

impl<'a> !Send for Ctx<'a>

§

impl<'a> !Sync for Ctx<'a>

§

impl<'a> !UnwindSafe for Ctx<'a>

§

impl<'a> Freeze for Ctx<'a>

§

impl<'a> Unpin for Ctx<'a>

§

impl<'a> UnsafeUnpin for Ctx<'a>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. 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.