rustit/01_phase_rust_src/sv/src/main.rs

87 lines
1.8 KiB
Rust
Raw Normal View History

2024-04-05 18:34:08 +02:00
2024-04-05 21:12:55 +02:00
mod parser;
2024-04-05 18:34:08 +02:00
use std::env;
2024-04-06 00:33:10 +02:00
use std::process::exit;
2024-04-05 18:34:08 +02:00
2024-03-25 00:57:14 +01:00
fn main() {
2024-04-05 21:12:55 +02:00
2024-04-05 23:00:23 +02:00
// def env variables.
let svdir_env = env::var("SVDIR");
2024-04-05 23:10:11 +02:00
let svwait_env = env::var("SVWAIT");
2024-04-05 23:00:23 +02:00
let svdir_var = match svdir_env {
Ok(var) => var,
Err(..) => "/run/runit/service".to_string(),
};
2024-04-06 00:33:10 +02:00
let mut svwait_var = match svwait_env {
2024-04-05 23:10:11 +02:00
Ok(env) => match env.parse::<i32>() {
Ok(var) => var,
Err(..) => 7,
},
Err(..) => 7,
};
2024-04-06 00:33:10 +02:00
let mut verbose = 0;
2024-04-05 23:00:23 +02:00
dbg!(svdir_var);
2024-04-05 23:10:11 +02:00
dbg!(svwait_var);
2024-04-05 23:00:23 +02:00
// run the parser
let args: Vec<String> = env::args().collect();
2024-04-05 21:12:55 +02:00
let arg_parser: Vec<String> = parser::parse_args(args);
2024-04-06 00:33:10 +02:00
//dbg!(arg_parser);
let mut i = 0;
2024-04-06 00:41:24 +02:00
let mut command;
2024-04-06 00:33:10 +02:00
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.
}
2024-04-06 00:33:10 +02:00
parser::misc::usage();
exit(100);
}
}
2024-04-06 00:41:24 +02:00
else if i == 1 {
command = val;
dbg!(command);
i += 1;
}
2024-04-06 00:33:10 +02:00
// 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;
}
}
2024-04-05 21:12:55 +02:00
2024-04-05 21:12:55 +02:00
2024-03-25 00:57:14 +01:00
}