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
run:
$ cargo add argfetch
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::fetch;
let args: Vec<String> = env::args().collect(); let args_value = fetch(String::from("-d"), &args); if args_value.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::fetch;
let args: Vec<String> = env::args().collect();
let args_value = fetch(String::from("-a"), &args);
if args_value.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::fetch;
let args: Vec<String> = env::args().collect();
let a_args_value = fetch(String::from("-e"), &args);
if a_args_value.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
$