[][src]Struct seahorse::Context

pub struct Context {
    pub args: Vec<String>,
    // some fields omitted
}

Context type

This type is used only for Action arguments

Fields

args: Vec<String>

Vec<String> with flags and flag values ​​removed from command line arguments

Methods

impl Context[src]

pub fn new(args: Vec<String>, flags: Option<Vec<Flag>>) -> Self[src]

Create new instance of Context Parse processing using Vec<String> command line argument and Vec<Flag> as arguments

Example

use std::env;
use seahorse::{Context, Flag, FlagType};

let args: Vec<String> = env::args().collect();
let flag = Flag::new("bool", "cli cmd [arg] --bool", FlagType::Bool);
let context = Context::new(args, Some(vec![flag]));

pub fn bool_flag(&self, name: &str) -> bool[src]

Get bool flag

Example

use std::env;
use seahorse::{Context, Flag, FlagType};

let args: Vec<String> = env::args().collect();
let flag = Flag::new("bool", "cli cmd [arg] --bool", FlagType::Bool);
let context = Context::new(args, Some(vec![flag]));

if context.bool_flag("bool") {
    println!("true");
}

pub fn string_flag(&self, name: &str) -> Option<String>[src]

Get string flag

Example

use std::env;
use seahorse::{Context, Flag, FlagType};

let args: Vec<String> = env::args().collect();
let flag = Flag::new("string", "cli cmd [arg] --string [string]", FlagType::String);
let context = Context::new(args, Some(vec![flag]));

match context.string_flag("string") {
    Some(s) => println!("{}", s),
    None => println!("Not found string...")
}

pub fn int_flag(&self, name: &str) -> Option<isize>[src]

Get int flag

Example

use std::env;
use seahorse::{Context, Flag, FlagType};

let args: Vec<String> = env::args().collect();
let flag = Flag::new("int", "cli cmd [arg] --int [int]", FlagType::Int);
let context = Context::new(args, Some(vec![flag]));

match context.int_flag("int") {
    Some(i) => println!("{}", i),
    None => println!("Not found int number...")
}

pub fn float_flag(&self, name: &str) -> Option<f64>[src]

Get float flag

Example

use std::env;
use seahorse::{Context, Flag, FlagType};

let args: Vec<String> = env::args().collect();
let flag = Flag::new("float", "cli cmd [arg] --float [float]", FlagType::Float);
let context = Context::new(args, Some(vec![flag]));

match context.float_flag("float") {
    Some(f) => println!("{}", f),
    None => println!("Not found float number...")
}

Auto Trait Implementations

impl RefUnwindSafe for Context

impl Send for Context

impl Sync for Context

impl Unpin for Context

impl UnwindSafe for Context

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.