use clap::ArgMatches; use qsu::{installer::RegSvc, rt::SrvAppRt}; use crate::err::Error; pub struct AppArgsProc { pub(crate) bldr: Box SrvAppRt> } impl qsu::argp::ArgsProc for AppArgsProc { type AppErr = Error; /// Process an `register-service` subcommand. fn proc_inst( &mut self, _sub_m: &ArgMatches, regsvc: RegSvc ) -> Result { // This is split out into its own function because the orphan rule wouldn't // allow the application to implement a std::io::Error -> qsu::AppErr // conversion in one go, so we do it in two steps instead. // proc_inst_inner()'s '?' converts "all" errors into 'Error`. // The proc_inst() method's `?` converts from `Error` to `qsu::AppError` proc_inst_inner(regsvc) } fn build_apprt(&mut self) -> Result, Self::AppErr> { Ok((self.bldr)()) } } fn proc_inst_inner(regsvc: RegSvc) -> Result { // Use current working directory as the service's workdir let cwd = std::env::current_dir()?.to_str().unwrap().to_string(); let mut regsvc = regsvc .workdir(cwd) .env("HOLY", "COW") .env("Private", "Public") .env("General", "Specific"); // Set display name, but only if it wasn't already specified on the command // line if regsvc.display_name.is_none() { regsvc.display_name_ref("Hello Service"); } // Hard-code servie as supporting conf-reload service events. let regsvc = regsvc.conf_reload(); // Add a callback that will increase log and trace levels by deafault. #[cfg(windows)] let regsvc = regsvc.regconf(|_svcname, params| { // Leave a key/value pair in the registry as a hello params.set_value("AppArgParser", &"SaysHello")?; Ok(()) }); Ok(regsvc) } // vim: set ft=rust et sw=2 ts=2 sts=2 cinoptions=2 tw=79 :