pub struct ArgSpec { /* private fields */ }
Expand description
Specifies the valid arguments of the program and is used to parse
the command-line arguments into an [Arg
].
Implementations§
Source§impl ArgSpec
impl ArgSpec
Sourcepub fn build() -> ArgSpecBuilder
pub fn build() -> ArgSpecBuilder
Creates an ArgSpecBuilder
that can be used to build the ArgSpec
.
§Example
use easy_args::ArgSpec;
let spec = ArgSpec::build()
.boolean("arg1")
.done()
.unwrap();
Sourcepub fn has_arg(&self, name: impl Into<String>, ty: ArgType) -> bool
pub fn has_arg(&self, name: impl Into<String>, ty: ArgType) -> bool
Determines if an argument of a given name and ArgType
exists
within the ArgSpec
.
§Example
use easy_args::{arg_spec, ArgType};
let spec = arg_spec!(username: String);
if spec.has_arg("username", ArgType::String) {
let args = spec.parse().unwrap();
if let Some(username) = args.string("username") {
// do something with username
}
}
Sourcepub fn parse(&self) -> Result<Args>
pub fn parse(&self) -> Result<Args>
Parses the command-line arguments and Returns [Ok(Args)
] if there
were no parse errors and [Err(Error)
] if otherwise.
§Example
use easy_args::arg_spec;
let spec = arg_spec!(vsync: bool);
match spec.parse() {
Ok(args) => {
// do stuff with the arguments
}
Err(err) => eprintln!("{:?}", err),
}
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ArgSpec
impl RefUnwindSafe for ArgSpec
impl Send for ArgSpec
impl Sync for ArgSpec
impl Unpin for ArgSpec
impl UnwindSafe for ArgSpec
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