refactor main
This commit is contained in:
parent
06d9373d4b
commit
37f89a3521
31
src/main.rs
31
src/main.rs
@ -31,21 +31,10 @@ struct Cli {
|
|||||||
command: Command,
|
command: Command,
|
||||||
}
|
}
|
||||||
|
|
||||||
macro_rules! handle_error {
|
|
||||||
($name:expr, $res:expr) => {
|
|
||||||
match $res {
|
|
||||||
Err(e) => {
|
|
||||||
log::error!("{} error: {:#?}", $name, e)
|
|
||||||
}
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let args = Cli::parse();
|
let args = Cli::parse();
|
||||||
|
|
||||||
let _logger = Logger::try_with_str("info")
|
let logger = Logger::try_with_str("info")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.log_to_file(
|
.log_to_file(
|
||||||
FileSpec::default().directory(std::env::current_exe().unwrap().parent().unwrap()),
|
FileSpec::default().directory(std::env::current_exe().unwrap().parent().unwrap()),
|
||||||
@ -67,11 +56,17 @@ fn main() {
|
|||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
match args.command {
|
let res = match args.command {
|
||||||
Command::Install => handle_error!("install", service::install()),
|
Command::Install => service::install(),
|
||||||
Command::Uninstall => handle_error!("uninstall", service::uninstall()),
|
Command::Uninstall => service::uninstall(),
|
||||||
Command::Run => handle_error!("run", service::run()),
|
Command::Run => service::run(),
|
||||||
Command::Start => handle_error!("start", service::start()),
|
Command::Start => service::start(),
|
||||||
Command::Stop => handle_error!("stop", service::stop()),
|
Command::Stop => service::stop(),
|
||||||
|
};
|
||||||
|
|
||||||
|
if let Err(e) = res {
|
||||||
|
log::error!("{:?} error: {:#?}", args.command, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
drop(logger);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user