Compare commits

...

1 Commits
v1.0.3 ... main

Author SHA1 Message Date
Ian Wijma e3623f4ecc Refactor argument handling in main.rs for increased readability
The argument handling in main.rs has been adjusted to utilize argument destructuring, making the code more readable and organized. Additionally, the unnecessary new lines were removed, and commas were added to the last elements of the 'Arguments' struct to follow Rust norms and increase consistency.
2024-01-06 19:57:04 +11:00
1 changed files with 10 additions and 9 deletions

View File

@ -17,7 +17,7 @@ struct Arguments {
delay: u8, delay: u8,
#[arg()] #[arg()]
command: String command: String,
} }
const SECONDS_IN_A_MINUTE: u16 = 60; const SECONDS_IN_A_MINUTE: u16 = 60;
@ -29,7 +29,7 @@ struct Retry {
max_retries: u8, max_retries: u8,
timespan: u16, timespan: u16,
restart_delay: u8, restart_delay: u8,
restart_name: String restart_name: String,
} }
fn main() { fn main() {
@ -39,22 +39,23 @@ fn main() {
let mut timespan = SECONDS_IN_A_MINUTE; let mut timespan = SECONDS_IN_A_MINUTE;
let mut restart_name = String::from("minute"); let mut restart_name = String::from("minute");
if arguments.per_minute > 0 { let Arguments { per_minute, per_hour, .. } = arguments;
max_retries = arguments.per_minute; if per_minute > 0 {
} else if arguments.per_hour > 0 { max_retries = per_minute;
max_retries = arguments.per_hour; } else if per_hour > 0 {
max_retries = per_hour;
timespan = SECONDS_IN_A_HOUR; timespan = SECONDS_IN_A_HOUR;
restart_name = String::from("hour"); restart_name = String::from("hour");
} }
let Arguments { command, delay: restart_delay, .. } = arguments;
let retry: Retry = Retry { let retry: Retry = Retry {
max_retries, max_retries,
timespan, timespan,
restart_name, restart_name,
command: arguments.command, command,
restart_delay,
history: Vec::new(), history: Vec::new(),
restart_delay: arguments.delay,
}; };
run_command(retry) run_command(retry)