mirror of
https://github.com/egor-white/zaprett.git
synced 2025-12-10 05:19:42 +05:00
fix set-autostart command
This commit is contained in:
@@ -2,19 +2,20 @@ use crate::MODULE_PATH;
|
|||||||
use tokio::fs;
|
use tokio::fs;
|
||||||
use tokio::fs::File;
|
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");
|
let autostart_path = MODULE_PATH.join("autostart");
|
||||||
|
|
||||||
if autostart {
|
if !get_autostart() {
|
||||||
File::create(autostart_path).await?;
|
File::create(MODULE_PATH.join("autostart")).await?;
|
||||||
} else {
|
} else {
|
||||||
fs::remove_file(autostart_path).await?;
|
fs::remove_file(autostart_path).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println!("{}", get_autostart());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_autostart() {
|
pub fn get_autostart() -> bool {
|
||||||
let file = MODULE_PATH.join("autostart");
|
return MODULE_PATH.join("autostart").exists();
|
||||||
println!("{}", file.exists());
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,11 +19,7 @@ pub enum Command {
|
|||||||
Status,
|
Status,
|
||||||
|
|
||||||
/// Enable or disable automatic restart
|
/// Enable or disable automatic restart
|
||||||
SetAutostart {
|
SetAutostart,
|
||||||
/// Whether to enable (true) or disable (false) autostart
|
|
||||||
#[arg(value_parser = clap::value_parser!(bool))]
|
|
||||||
autostart: bool,
|
|
||||||
},
|
|
||||||
|
|
||||||
/// Show whether autostart is enabled
|
/// Show whether autostart is enabled
|
||||||
GetAutostart,
|
GetAutostart,
|
||||||
@@ -59,12 +55,12 @@ impl Command {
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
Command::SetAutostart { autostart } => {
|
Command::SetAutostart => {
|
||||||
if let Err(err) = set_autostart(*autostart).await {
|
if let Err(err) = set_autostart().await {
|
||||||
error!("Failed to set auto start: {err}")
|
error!("Failed to set auto start: {err}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Command::GetAutostart => get_autostart(),
|
Command::GetAutostart => println!("{}", get_autostart()),
|
||||||
Command::ModuleVersion => println!("{}", module_version().await?),
|
Command::ModuleVersion => println!("{}", module_version().await?),
|
||||||
Command::BinaryVersion => println!("{}", bin_version()),
|
Command::BinaryVersion => println!("{}", bin_version()),
|
||||||
Command::Args { args } => run_nfqws(&args.join(" "))?,
|
Command::Args { args } => run_nfqws(&args.join(" "))?,
|
||||||
|
|||||||
Reference in New Issue
Block a user