4 Commits

Author SHA1 Message Date
CherretGit
f29ed9de63 change path 2025-11-17 21:32:48 +07:00
CherretGit
d58792fbfc fix set-autostart command 2025-11-17 21:27:52 +07:00
white
860dc21272 fix args joining 2025-11-11 19:13:47 +03:00
CherretGit
277f6756bd add args command and optimize binary 2025-11-11 20:48:21 +07:00
3 changed files with 20 additions and 15 deletions

View File

@@ -30,3 +30,4 @@ panic = "abort"
opt-level = "z"
lto = true
strip = true
codegen-units = 1

View File

@@ -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 {
if !get_autostart() {
File::create(autostart_path).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();
}

View File

@@ -1,8 +1,8 @@
use crate::autostart::{get_autostart, set_autostart};
use crate::service::{restart_service, service_status, start_service, stop_service};
use crate::{bin_version, module_version};
use crate::{bin_version, module_version, run_nfqws};
use clap::Subcommand;
use log::error;
use crate::autostart::{get_autostart, set_autostart};
#[derive(Subcommand)]
pub enum Command {
@@ -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,
@@ -33,6 +29,12 @@ pub enum Command {
/// Show the nfqws binary version
BinaryVersion,
/// Run nfqws
Args {
#[arg(allow_hyphen_values=true, trailing_var_arg = true, num_args = 0..)]
args: Vec<String>,
},
}
impl Command {
@@ -53,14 +55,15 @@ 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(" "))?,
}
Ok(())