mod parser; use std::env; use std::process::exit; fn main() { // def env variables. let svdir_env = env::var("SVDIR"); let svwait_env = env::var("SVWAIT"); let svdir_var = match svdir_env { Ok(var) => var, Err(..) => "/run/runit/service".to_string(), }; let mut svwait_var = match svwait_env { Ok(env) => match env.parse::() { Ok(var) => var, Err(..) => 7, }, Err(..) => 7, }; let mut verbose = 0; dbg!(svdir_var); dbg!(svwait_var); // run the parser let args: Vec = env::args().collect(); let arg_parser: Vec = parser::parse_args(args); //dbg!(arg_parser); let mut i = 0; let mut command; 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 { if val.len() == 2 { println!("sv: illegal option -- {}", val.chars().nth(1).unwrap() ); // TODO: thread NOT pannic if it is not an ASCII character. } parser::misc::usage(); exit(100); } } else if i == 1 { command = val; dbg!(command); i += 1; } // TODO: Exec the command on all given services. else if i == 3 { svwait_var = match val.parse::() { Ok(val) => val, Err(..) => svwait_var, }; dbg!(svwait_var); i = 0; } } }