flags #5

Merged
statzitz merged 5 commits from flags into main 2024-04-06 00:47:55 +02:00
Showing only changes of commit d1ebe941d4 - Show all commits

View file

@ -1,8 +1,8 @@
//mod misc;
mod parser; mod parser;
use std::env; use std::env;
use std::process::exit;
fn main() { fn main() {
@ -15,7 +15,7 @@ fn main() {
Err(..) => "/run/runit/service".to_string(), Err(..) => "/run/runit/service".to_string(),
}; };
let svwait_var = match svwait_env { let mut svwait_var = match svwait_env {
Ok(env) => match env.parse::<i32>() { Ok(env) => match env.parse::<i32>() {
Ok(var) => var, Ok(var) => var,
Err(..) => 7, Err(..) => 7,
@ -23,6 +23,8 @@ fn main() {
Err(..) => 7, Err(..) => 7,
}; };
let mut verbose = 0;
dbg!(svdir_var); dbg!(svdir_var);
dbg!(svwait_var); dbg!(svwait_var);
@ -32,12 +34,43 @@ fn main() {
let arg_parser: Vec<String> = parser::parse_args(args); let arg_parser: Vec<String> = parser::parse_args(args);
dbg!(arg_parser); //dbg!(arg_parser);
// TODO: Interpret the flags given if some are given.
let mut i = 0;
for val in arg_parser.iter() {
if i == 0 {
if val == "-v" {
verbose = 1;
dbg!(verbose);
}
else if val == "-w" {
i = 3;
// take next parametter before returning to i = 0.
}
else if val == "--" {
i += 1;
}
else {
parser::misc::usage();
exit(100);
}
}
// TODO: Set the command if it is given // TODO: Set the command if it is given
// TODO: Exec the command on all given services. // TODO: Exec the command on all given services.
else if i == 3 {
svwait_var = match val.parse::<i32>() {
Ok(val) => val,
Err(..) => svwait_var,
};
dbg!(svwait_var);
i = 0;
}
}