Add pre_check checking

This commit is contained in:
ByteDream 2022-12-07 20:08:44 +01:00
parent c383b4d307
commit 933d217b63

View file

@ -152,18 +152,28 @@ pub async fn cli_entrypoint() {
.unwrap(); .unwrap();
debug!("Created ctrl-c handler"); debug!("Created ctrl-c handler");
let result = match cli.command { match cli.command {
Command::Archive(archive) => archive.execute(ctx).await, Command::Archive(archive) => execute_executor(archive,ctx).await,
Command::Download(download) => download.execute(ctx).await, Command::Download(download) => execute_executor(download, ctx).await,
Command::Login(login) => { Command::Login(login) => {
if login.remove { if login.remove {
Ok(()) return;
} else { } else {
login.execute(ctx).await execute_executor(login, ctx).await
} }
} }
}; };
if let Err(err) = result { }
/// Cannot be done in the main function. I wanted to return `dyn` [`Execute`] from the match but had to
/// box it which then conflicts with [`Execute::execute`] which consumes `self`
async fn execute_executor(executor: impl Execute, ctx: Context) {
if let Err(err) = executor.pre_check() {
error!("Misconfigurations detected: {}", err);
std::process::exit(1)
}
if let Err(err) = executor.execute(ctx).await {
error!("a unexpected error occurred: {}", err); error!("a unexpected error occurred: {}", err);
std::process::exit(1) std::process::exit(1)
} }