implem_command #9

Merged
statzitz merged 13 commits from implem_command into main 2024-04-18 01:30:48 +02:00
5 changed files with 45 additions and 32 deletions
Showing only changes of commit 92e01299bc - Show all commits

View file

@ -1,41 +1,17 @@
pub mod sent_signal;
use crate::status_obj;
pub mod execute_service;
pub fn execute(svdir_var: String, svwait_var: i32, verbose: i8, command: &str, services: Vec<String>) -> i32{
// split a service vector into different sv.
let mut exit_code: i32 = 0;
for sv in services {
let ch1 = sv.chars().next().unwrap();
let ch2_row = &sv.chars().collect::<Vec<_>>()[..2];
let ch2: String = ch2_row.into_iter().collect();
let path;
if ch1 == '/' || ch2 == "~/"{
// case absolute path for the service
//
path = sv.clone();
} else {
// case relative path for the service.
//
path = svdir_var.clone() + "/" + &sv;
exit_code += execute_service::execute_service(svdir_var.clone(), svwait_var, verbose, command, sv);
if exit_code > 99 {
exit_code = 99;
}
let status_option = status_obj::StatusObj::new(path, sv);
match status_option {
Some(status) => {
exit_code += sent_signal::sent_signal(svwait_var, verbose, command, status);
},
None => {
if exit_code < 99 {
exit_code += 1;
}
},
};
}
return exit_code
}

View file

@ -0,0 +1,22 @@
mod sent_signal;
mod make_path;
use crate::status_obj;
pub fn execute_service(svdir_var: String, svwait_var: i32, verbose: i8, command: &str, sv: String) -> i32 {
// make a sv object from a string, svdir_var, and sent it the command signal.
let path = make_path::make_path(svdir_var, sv.clone());
let status_option = status_obj::StatusObj::new(path, sv);
match status_option {
Some(status) => {
return sent_signal::sent_signal(svwait_var, verbose, command, status);
},
None => {
return 1;
},
};
}

View file

@ -0,0 +1,17 @@
pub fn make_path(svdir_var: String, sv: String) -> String {
let ch1 = sv.chars().next().unwrap();
let ch2_row = &sv.chars().collect::<Vec<_>>()[..2];
let ch2: String = ch2_row.into_iter().collect();
let path;
if ch1 == '/' || ch2 == "~/"{
// case absolute path for the service
path = sv;
} else {
// case relative path for the service.
path = svdir_var + "/" + &sv;
}
return path
}

View file

@ -31,5 +31,3 @@ pub fn sent_signal( svwait_var: i32, verbose: i8, command: &str, mut sv: status_
};
}