Updated structs in managers module

This commit is contained in:
kdeng00
2024-04-08 16:17:55 -04:00
parent 3bd2d6175b
commit 82ab9142e6
2 changed files with 111 additions and 23 deletions
+109 -21
View File
@@ -2,8 +2,6 @@ use serde::{Deserialize, Serialize};
use crate::models; use crate::models;
// mod managers {
#[derive(Debug, Deserialize, Serialize)] #[derive(Debug, Deserialize, Serialize)]
pub struct ActionManager { pub struct ActionManager {
pub action: String, pub action: String,
@@ -13,40 +11,130 @@ pub struct ActionManager {
} }
impl ActionManager { impl ActionManager {
// TODO: Implement
pub fn retrieve_icarus_action(&self) -> models::icarus_action::IcarusAction { pub fn retrieve_icarus_action(&self) -> models::icarus_action::IcarusAction {
return models::icarus_action::IcarusAction { return models::icarus_action::IcarusAction {
action: String::from(""), flags: self.flags.clone(),
flags: Vec::new(), action: String::from(&self.action),
}; };
} }
// TODO: Implement
fn supported_flags(&self) -> Vec<String> { fn supported_flags(&self) -> Vec<String> {
return Vec::new(); return vec![String::from("-u"),
String::from("-p"),
String::from("-t"),
String::from("-h"),
String::from("-s"),
String::from("-sd"),
String::from("-sr"),
String::from("-d"),
String::from("-D"),
String::from("-b"),
String::from("-rt"),
String::from("-nc"),
String::from("-m"),
String::from("-ca"),
String::from("-smca"),
String::from("-t"),
];
} }
// TODO: Implement // TODO: Implement
fn supported_actions(&self) {} fn supported_actions(&self) {}
// TODO: Implement
fn initialize(&self) {} pub fn initialize(&mut self) {
// TODO: Implement self.validate_flags();
fn validate_flags(&self) {} self.action = self.action.to_lowercase();
// TODO: Implement }
fn validate_flags(&mut self) {
println!("Validating flags");
let flag_vals = self.parsed_flags();
for i in 0..flag_vals.len() {
let flag = &flag_vals[i];
println!("Value: {}", flag);
let mut flg = models::flags::Flags::default();
if self.is_valid_flag(flag) && self.does_flag_have_value(flag) {
println!("Flag has value");
flg.flag = String::from(flag);
flg.value = String::from(&flag_vals[i+1]);
} else if self.is_valid_flag(flag) {
println!("Flag does not have a value");
flg.flag = String::from(flag);
} else {
println!("Flag {} is not valid", flag);
std::process::exit(-1);
}
self.flags.push(flg);
}
}
fn is_valid_flag(&self, flag: &String) -> bool { fn is_valid_flag(&self, flag: &String) -> bool {
return false; let flags = self.supported_flags();
let mut found: bool = false;
for flg in &flags {
if flg == flag {
found = true;
break;
} }
// TODO: Implement }
return found;
}
fn does_flag_have_value(&self, flag: &String) -> bool { fn does_flag_have_value(&self, flag: &String) -> bool {
let flags_tmp = self.parsed_flags();
let mut i_found: i32 = -1;
for i in 0..flags_tmp.len() {
let flg = &flags_tmp[i];
if flg == flag {
i_found = i as i32;
break;
}
}
if i_found >= 0 {
if (i_found + 1) < flags_tmp.len().try_into().unwrap() {
return true;
} else {
return false; return false;
} }
// TODO: Implement } else {
fn print_action(&self) {} return false;
// TODO: Implement }
fn print_flags(&self) {} }
// TODO: Implement
fn print_action(&self) {
if self.action.len() == 0 {
println!("Action is empty");
} else {
println!("Action is {}", self.action);
}
}
fn print_flags(&self) {
println!("Printing flags...");
for flag in &self.flags {
println!("Flag {}", flag.flag);
println!("Value {}", flag.value);
}
}
fn parsed_flags(&self) -> Vec<String> { fn parsed_flags(&self) -> Vec<String> {
return Vec::new(); let mut parsed: Vec<String> = Vec::new();
for i in 2..self.params.len() {
let flag = String::from(&self.params[i]);
parsed.push(flag);
}
return parsed;
} }
} }
// }
+1 -1
View File
@@ -2,7 +2,7 @@ use std::default::Default;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)] #[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Flags { pub struct Flags {
pub flag: String, pub flag: String,
pub value: String, pub value: String,