mirror of
https://github.com/crunchy-labs/crunchy-cli.git
synced 2026-01-21 04:02:00 -06:00
Execute cli pre-check before logging in
This commit is contained in:
parent
f584c8028f
commit
d8d1f8a443
1 changed files with 10 additions and 4 deletions
|
|
@ -120,7 +120,7 @@ struct LoginMethod {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn cli_entrypoint() {
|
pub async fn cli_entrypoint() {
|
||||||
let cli: Cli = Cli::parse();
|
let mut cli: Cli = Cli::parse();
|
||||||
|
|
||||||
if let Some(verbosity) = &cli.verbosity {
|
if let Some(verbosity) = &cli.verbosity {
|
||||||
if verbosity.v as u8 + verbosity.q as u8 + verbosity.vv as u8 > 1 {
|
if verbosity.v as u8 + verbosity.q as u8 + verbosity.vv as u8 > 1 {
|
||||||
|
|
@ -139,6 +139,12 @@ pub async fn cli_entrypoint() {
|
||||||
|
|
||||||
debug!("cli input: {:?}", cli);
|
debug!("cli input: {:?}", cli);
|
||||||
|
|
||||||
|
match &mut cli.command {
|
||||||
|
Command::Archive(archive) => pre_check_executor(archive).await,
|
||||||
|
Command::Download(download) => pre_check_executor(download).await,
|
||||||
|
Command::Login(login) => pre_check_executor(login).await,
|
||||||
|
};
|
||||||
|
|
||||||
let ctx = match create_ctx(&cli).await {
|
let ctx = match create_ctx(&cli).await {
|
||||||
Ok(ctx) => ctx,
|
Ok(ctx) => ctx,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
|
|
@ -191,14 +197,14 @@ pub async fn cli_entrypoint() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Cannot be done in the main function. I wanted to return `dyn` [`Execute`] from the match but had to
|
async fn pre_check_executor(executor: &mut impl Execute) {
|
||||||
/// box it which then conflicts with [`Execute::execute`] which consumes `self`
|
|
||||||
async fn execute_executor(mut executor: impl Execute, ctx: Context) {
|
|
||||||
if let Err(err) = executor.pre_check() {
|
if let Err(err) = executor.pre_check() {
|
||||||
error!("Misconfigurations detected: {}", err);
|
error!("Misconfigurations detected: {}", err);
|
||||||
std::process::exit(1)
|
std::process::exit(1)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async fn execute_executor(executor: impl Execute, ctx: Context) {
|
||||||
if let Err(err) = executor.execute(ctx).await {
|
if let Err(err) = executor.execute(ctx).await {
|
||||||
error!("a unexpected error occurred: {}", err);
|
error!("a unexpected error occurred: {}", err);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue