use std::path::PathBuf;
use clap::Parser;
#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
struct Args {
#[command(subcommand)]
cmd: Option<Commands>,
}
#[derive(Parser, Debug)]
enum Commands {
Start,
Stop,
Restart,
Debug,
#[command(long_about = "
Creates a new config file, or prints info about the active one.
The configuration scheme is detailed at https://github.com/sylvanfranklin/srhd
")]
Config,
}
fn main() {
let args = Args::parse();
if let Some(cmd) = args.cmd {
let service = launchctl::Service::new(
"com.sylvanfranklin.srhd",
PathBuf::from(std::env::current_exe().unwrap()),
);
srhd::service::install(&service).unwrap();
use Commands::*;
match cmd {
Start => service.start().expect("Failed to start service"),
Stop => service.stop().expect("Failed to stop service"),
Restart => service.restart().expect("Failed to restart service"),
Config => println!(".config/srhd/srhd.toml"),
Debug => srhd::listener::srhd_process(true),
}
} else {
srhd::listener::srhd_process(false);
}
}