[−][src]Struct dia_args::Args
Arguments
Usage
cmds()
can contain commands and normal arguments (such as file paths...)sub_args()
are not verified. They are the ones after--
symbol, which are meant for being passed to sub processes.
Methods
impl Args
[src]
pub fn cmd(&self) -> Option<&str>
[src]
pub fn cmds(&self) -> Option<Vec<&str>>
[src]
Gets the commands
If it's some vector, the vector is not empty.
pub fn args(&self) -> &HashMap<String, Vec<String>>
[src]
pub fn sub_args(&self) -> Option<Vec<&str>>
[src]
Sub arguments
If it's some vector, the vector is not empty.
pub fn is_empty(&self) -> bool
[src]
pub fn has_args(&self) -> bool
[src]
pub fn use_stdin(&self) -> bool
[src]
pub fn sub_cmd(self) -> (Option<String>, Self)
[src]
Transforms into sub command
For example:
- Command line:
program help version 1
- First parse:
help version 1
- After calling this function:
version 1
use dia_args; const CMD_VERSION: &str = "version"; let (cmd, args) = dia_args::parse().unwrap().sub_cmd(); match cmd.as_ref().map(|s| s.as_str()) { Some(CMD_VERSION) => match args.is_empty() { true => println!("Version: ..."), false => eprintln!("{:?} command doesn't take arguments", CMD_VERSION), }, Some(other) => eprintln!("Command {:?} not supported", other), None => eprintln!("Missing command"), };
pub fn get<T, S>(&self, keys: &[S]) -> Result<Option<T>> where
T: FromStr,
S: AsRef<str>,
[src]
T: FromStr,
S: AsRef<str>,
Gets a value
You can provide multiple keys as you want. But the user can only provide one single key of them. This function can be used for short version and long version of your keys.
Examples
use dia_args; let args = dia_args::parse_strings(["--type", "ogg"].into_iter()).unwrap(); assert_eq!(args.get::<String, _>(&["-t", "--type"]).unwrap().unwrap(), "ogg"); let args = dia_args::parse_strings(["--type", "ogg"].into_iter()).unwrap(); assert!(args.get::<String, _>(&["-t"]).unwrap().is_none()); let args = dia_args::parse_strings(["--type", "ogg", "-t", "some"].into_iter()).unwrap(); args.get::<String, _>(&["-t", "--type"]).unwrap_err();
pub fn take<T, S>(&mut self, keys: &[S]) -> Result<Option<T>> where
T: FromStr,
S: AsRef<str>,
[src]
T: FromStr,
S: AsRef<str>,
Calls get()
and removes the keys if the result is Ok(Some)
Examples
use dia_args; let mut args = dia_args::parse_strings(["--type", "rs"].into_iter()).unwrap(); assert_eq!(args.take::<String, _>(&["--type"]).unwrap().unwrap(), "rs"); assert!(args.get::<String, _>(&["--type"]).unwrap().is_none());
pub fn get_vec<T, S>(&self, keys: &[S]) -> Result<Option<Vec<T>>> where
T: FromStr,
S: AsRef<str>,
[src]
T: FromStr,
S: AsRef<str>,
Gets a vector of values
Examples
use dia_args; let args = dia_args::parse_strings( &mut ["--type", "ogg", "-t", "m4v", "--type", "md", "-t", "rs"].into_iter() ) .unwrap(); let mut types = args.get_vec::<String, _>(&["-t", "--type"]).unwrap().unwrap(); types.sort(); assert_eq!(types, &["m4v", "md", "ogg", "rs"]);
pub fn take_vec<T, S>(&mut self, keys: &[S]) -> Result<Option<Vec<T>>> where
T: FromStr,
S: AsRef<str>,
[src]
T: FromStr,
S: AsRef<str>,
Calls get_vec()
and removes the keys if the result is Ok(Some)
Examples
use dia_args; let mut args = dia_args::parse_strings(["-l", "c", "-l", "c++"].into_iter()).unwrap(); let mut languages = args.take_vec::<String, _>(&["-l"]).unwrap().unwrap(); languages.sort(); assert_eq!(languages, &["c", "c++"]); assert!(args.is_empty());
pub fn take_cmds(&mut self) -> Option<Vec<String>>
[src]
Takes commands out
Examples
use dia_args; let mut args = dia_args::parse_strings(["do", "this", "--faster=true"].into_iter()).unwrap(); assert_eq!(args.take_cmds().unwrap(), &["do", "this"]);
pub fn take_sub_args(&mut self) -> Option<Vec<String>>
[src]
Takes sub arguments out
Examples
use dia_args; let mut args = dia_args::parse_strings(["eat", "chicken", "--", "with", "ronnie-coleman"].into_iter()).unwrap(); assert_eq!(args.take_sub_args().unwrap(), &["with", "ronnie-coleman"]);
Trait Implementations
Auto Trait Implementations
Blanket Implementations
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,