argfetch
command line argument parser for rust.
about
argfetch returns a string that has all the args separated by spaces
if the flag doesnt exist, or there is no value it will return an empty string
usage
either run:
$ cargo add argfetch
or add argfetch = "1.0" to your cargo.toml under [dependencies]
to use argfetch you have to pass flag you want to get the args from, and the vector of arguments
examples
in this example, we will be fetching the d flag:
fn main() {
use argfetch::parse;
let args: Vec<String> = env::args().collect(); let a_args = parse(String::from("-d"), &args); if a_args.is_empty() { println!("the flag is missing, or is empty");
std::process::exit(1); }
println!("{}", a_args);
}
running this code would output:
$ argfetch-example -d "hi" -a test -e some args
hi
$
instead if you wanted to fetch the a flag, you would do:
fn main() {
use argfetch::parse;
let args: Vec<String> = env::args().collect();
let a_args = parse(String::from("-a"), &args);
if a_args.is_empty() {
println!("the flag is missing, or is empty");
std::process::exit(1);
}
}
then the output would be:
$ argfetch-example -d "hi" -a test -e some args
test
$
and for getting the e flag:
fn main() {
use argfetch::parse;
let args: Vec<String> = env::args().collect();
let a_args = parse(String::from("-e"), &args);
if a_args.is_empty() {
println!("the flag is missing, or is empty");
std::process::exit(1);
}
}
then run:
$ argfetch-example -d "hi" -a test -e some args
some args
$
however, running it with no e flag, will output:
$ argfetch-example -d "hi" -a test
the flag is missing, or is empty
$