Struct Helper

Source
pub struct Helper { /* private fields */ }
Expand description

Helper

Implementations§

Source§

impl Helper

Source

pub fn name(&self) -> &String

name

Source

pub fn version(&self) -> &String

version

Source

pub fn desc(&self) -> &String

description

Source

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

name, email

Source

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

url_name, url

Source§

impl Helper

Source

pub fn current_cmd(&self) -> Option<&String>

Source

pub fn current_cmd_str(&self) -> Option<&str>

Source

pub fn current_cmd_ref(&self) -> &Option<String>

Source

pub fn current_exe(&self) -> Option<&String>

Source

pub fn current_dir(&self) -> Option<&String>

Source

pub fn home_dir(&self) -> Option<&String>

Source

pub fn temp_dir(&self) -> &String

Source

pub fn args_len(&self) -> &usize

You can do something if the length of arguments satisfys a condition.

Example: Print the help message when args.len() is 0.

let helper= {
    ...
};
if helper.args_len() == 0 
{
    helper.help_exit(0);
}
Source

pub fn as_helps(&self) -> &Helps

Source

pub fn as_mut_helps(&mut self) -> &mut Helps

Source§

impl Helper

Source

pub fn exit(&self, status: i32)

exit with the status

Source

pub fn ver(&self) -> &String

format!("{} {}", self.name(), self.version())

Source

pub fn ver_exit(&self, status: i32)

print ver(self.ver) message and exit with the status

Source

pub fn err<E>(&self, error: E) -> String
where E: AsRef<str> + Display,

format!("ERROR:\n {}\n\n", error)

Source

pub fn err_exit<E>(&self, error: E, status: i32)
where E: AsRef<str> + Display,

print error(self.err(error)) message to stderr and exit with the status

Source

pub fn err_line_print(&self, msg: &str, line_color: Color)

print error message line(2) with Red color(fg)

Source

pub fn help(&self) -> String

main’s help mesage

Source

pub fn help_exit(&self, status: i32)

print main’s help message and exit with the status

Source

pub fn help_err<E>(&self, error: E) -> String
where E: AsRef<str> + Display,

self.err(error) + self.help()

Source

pub fn help_err_exit<E>(&self, error: E, status: i32)
where E: AsRef<str> + Display,

print error and help message(self.help_err(error)) to stderr and exit with the status

Source

pub fn help_cmd(&self, cmd_name: &Option<String>) -> String

get sub_command’s help message

Source

pub fn help_cmd_exit(&self, cmd_name: &Option<String>, status: i32)

print sub_command’s help message and exit with the status

Source

pub fn help_cmd_err<E>(&self, cmd_name: &Option<String>, error: E) -> String
where E: AsRef<str> + Display,

self.err(error) + self.help_cmd(cmd_name)

Source

pub fn help_cmd_err_exit<E>( &self, cmd_name: &Option<String>, error: E, status: i32, )
where E: AsRef<str> + Display,

print error and sub_command’s help message to stderr,s exit with the status

Trait Implementations§

Source§

impl Debug for Helper

Source§

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

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

impl Default for Helper

Source§

fn default() -> Helper

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

Auto Trait Implementations§

§

impl Freeze for Helper

§

impl RefUnwindSafe for Helper

§

impl Send for Helper

§

impl Sync for Helper

§

impl Unpin for Helper

§

impl UnwindSafe for Helper

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.