Use a context struct
This commit is contained in:
parent
60208331ba
commit
a0d9bfa97b
10 changed files with 134 additions and 45 deletions
29
src/main.rs
29
src/main.rs
|
@ -12,6 +12,7 @@ use commands::server_features::server_features;
|
|||
use commands::server_version::server_version;
|
||||
use commands::sync_date_of_birth::sync_date_of_birth;
|
||||
use config::Config;
|
||||
use context::Context;
|
||||
use directories::ProjectDirs;
|
||||
use figment::providers::{Env, Format, Serialized, Toml};
|
||||
use figment::Figment;
|
||||
|
@ -22,6 +23,7 @@ use reqwest::header;
|
|||
mod args;
|
||||
mod commands;
|
||||
mod config;
|
||||
mod context;
|
||||
mod utils;
|
||||
|
||||
#[tokio::main]
|
||||
|
@ -51,29 +53,28 @@ async fn main() -> Result<()> {
|
|||
|
||||
let client = get_client(&conf.server_url, &conf.api_key)?;
|
||||
|
||||
validate_client_connection(&client).await?;
|
||||
let ctx = Context::builder()
|
||||
.client(client)
|
||||
.dry_run(args.dry_run)
|
||||
.no_confirm(args.no_confirm)
|
||||
.build();
|
||||
|
||||
validate_client_connection(&ctx.client).await?;
|
||||
|
||||
match &args.command {
|
||||
Commands::Assets { assets_command } => match assets_command {
|
||||
AssetsCommands::Delete { offline } => {
|
||||
delete_assets(&client, *offline, args.dry_run, args.no_confirm).await
|
||||
}
|
||||
AssetsCommands::List { offline } => list_assets(*offline, &client).await,
|
||||
AssetsCommands::Delete { offline } => delete_assets(ctx, *offline).await,
|
||||
AssetsCommands::List { offline } => list_assets(ctx, *offline).await,
|
||||
},
|
||||
Commands::People { people_command } => match people_command {
|
||||
PeopleCommands::MissingDateOfBirths {} => missing_date_of_birth(&client).await,
|
||||
PeopleCommands::MissingDateOfBirths {} => missing_date_of_birth(ctx).await,
|
||||
PeopleCommands::SyncDateOfBirths { vcard: _ } => {
|
||||
sync_date_of_birth(
|
||||
&client,
|
||||
&conf.people.sync_date_of_births.vcard,
|
||||
args.dry_run,
|
||||
)
|
||||
.await
|
||||
sync_date_of_birth(ctx, &conf.people.sync_date_of_births.vcard).await
|
||||
}
|
||||
},
|
||||
Commands::Server { server_command } => match server_command {
|
||||
ServerCommands::Features {} => server_features(&client).await,
|
||||
ServerCommands::Version {} => server_version(&client).await,
|
||||
ServerCommands::Features {} => server_features(ctx).await,
|
||||
ServerCommands::Version {} => server_version(ctx).await,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue