diff --git a/rust/crates/zaprett/src/autostart.rs b/rust/crates/zaprett/src/autostart.rs index f337fc2..0310574 100644 --- a/rust/crates/zaprett/src/autostart.rs +++ b/rust/crates/zaprett/src/autostart.rs @@ -2,19 +2,20 @@ use crate::MODULE_PATH; use tokio::fs; use tokio::fs::File; -pub async fn set_autostart(autostart: bool) -> Result<(), anyhow::Error> { +pub async fn set_autostart() -> Result<(), anyhow::Error> { let autostart_path = MODULE_PATH.join("autostart"); - if autostart { - File::create(autostart_path).await?; + if !get_autostart() { + File::create(MODULE_PATH.join("autostart")).await?; } else { fs::remove_file(autostart_path).await?; } + println!("{}", get_autostart()); + Ok(()) } -pub fn get_autostart() { - let file = MODULE_PATH.join("autostart"); - println!("{}", file.exists()); +pub fn get_autostart() -> bool { + return MODULE_PATH.join("autostart").exists(); } diff --git a/rust/crates/zaprett/src/cli/commands.rs b/rust/crates/zaprett/src/cli/commands.rs index eac0452..f8d9f2f 100644 --- a/rust/crates/zaprett/src/cli/commands.rs +++ b/rust/crates/zaprett/src/cli/commands.rs @@ -19,11 +19,7 @@ pub enum Command { Status, /// Enable or disable automatic restart - SetAutostart { - /// Whether to enable (true) or disable (false) autostart - #[arg(value_parser = clap::value_parser!(bool))] - autostart: bool, - }, + SetAutostart, /// Show whether autostart is enabled GetAutostart, @@ -59,12 +55,12 @@ impl Command { } ); } - Command::SetAutostart { autostart } => { - if let Err(err) = set_autostart(*autostart).await { + Command::SetAutostart => { + if let Err(err) = set_autostart().await { error!("Failed to set auto start: {err}") } } - Command::GetAutostart => get_autostart(), + Command::GetAutostart => println!("{}", get_autostart()), Command::ModuleVersion => println!("{}", module_version().await?), Command::BinaryVersion => println!("{}", bin_version()), Command::Args { args } => run_nfqws(&args.join(" "))?,