Cleanup install command

This commit is contained in:
Aleksey Kladov 2021-03-05 11:51:32 +03:00
parent 97b1550dda
commit 142f9a03fd
4 changed files with 56 additions and 51 deletions

View file

@ -1,5 +1,7 @@
#![allow(unreachable_pub)]
use crate::install::{ClientOpt, Malloc, ServerOpt};
xflags::args_parser! {
/// Run custom build command.
cmd xtask {
@ -137,3 +139,34 @@ impl Xtask {
}
}
// generated end
impl Install {
pub(crate) fn validate(&self) -> xflags::Result<()> {
if let Some(code_bin) = &self.code_bin {
if let Err(err) = code_bin.parse::<ClientOpt>() {
return Err(xflags::Error::new(format!("failed to parse `--code-bin`: {}", err)));
}
}
Ok(())
}
pub(crate) fn server(&self) -> Option<ServerOpt> {
if self.client && !self.server {
return None;
}
let malloc = if self.mimalloc {
Malloc::Mimalloc
} else if self.jemalloc {
Malloc::Jemalloc
} else {
Malloc::System
};
Some(ServerOpt { malloc })
}
pub(crate) fn client(&self) -> Option<ClientOpt> {
if !self.client && self.server {
return None;
}
let client_opt = self.code_bin.as_ref().and_then(|it| it.parse().ok()).unwrap_or_default();
Some(client_opt)
}
}