Use a context struct
This commit is contained in:
parent
60208331ba
commit
a0d9bfa97b
10 changed files with 134 additions and 45 deletions
|
@ -1,24 +1,19 @@
|
|||
use crate::{
|
||||
context::Context,
|
||||
utils::assets::{fetch_all_assets, AssetQuery},
|
||||
Client,
|
||||
};
|
||||
use color_eyre::eyre::Result;
|
||||
use dialoguer::{theme::ColorfulTheme, Confirm};
|
||||
use log::info;
|
||||
use uuid::Uuid;
|
||||
|
||||
pub async fn delete_assets(
|
||||
client: &Client,
|
||||
offline: bool,
|
||||
dry_run: bool,
|
||||
no_confirm: bool,
|
||||
) -> Result<()> {
|
||||
pub async fn delete_assets(ctx: Context, offline: bool) -> Result<()> {
|
||||
let query = AssetQuery {
|
||||
is_offline: if offline { Some(true) } else { None },
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let assets = fetch_all_assets(query, client).await?;
|
||||
let assets = fetch_all_assets(query, &ctx.client).await?;
|
||||
|
||||
for asset in &assets {
|
||||
info!(
|
||||
|
@ -27,8 +22,8 @@ pub async fn delete_assets(
|
|||
);
|
||||
}
|
||||
|
||||
if !dry_run {
|
||||
if !(no_confirm
|
||||
if !ctx.dry_run {
|
||||
if !(ctx.no_confirm
|
||||
|| Confirm::with_theme(&ColorfulTheme::default())
|
||||
.with_prompt("Do you want to continue?")
|
||||
.interact()?)
|
||||
|
@ -40,7 +35,7 @@ pub async fn delete_assets(
|
|||
.iter()
|
||||
.map(|asset| Uuid::parse_str(&asset.id))
|
||||
.collect();
|
||||
client
|
||||
ctx.client
|
||||
.delete_assets(&crate::types::AssetBulkDeleteDto {
|
||||
force: Some(true),
|
||||
ids: asset_ids?,
|
||||
|
@ -51,7 +46,7 @@ pub async fn delete_assets(
|
|||
info!(
|
||||
"Deleted {} assets{}",
|
||||
assets.len(),
|
||||
if dry_run { " (dry run)" } else { "" }
|
||||
if ctx.dry_run { " (dry run)" } else { "" }
|
||||
);
|
||||
|
||||
Ok(())
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{
|
||||
context::Context,
|
||||
utils::assets::{fetch_all_assets, AssetQuery},
|
||||
Client,
|
||||
};
|
||||
use color_eyre::eyre::Result;
|
||||
use tabled::{
|
||||
|
@ -20,13 +20,13 @@ struct Asset {
|
|||
model: String,
|
||||
}
|
||||
|
||||
pub async fn list_assets(offline: bool, client: &Client) -> Result<()> {
|
||||
pub async fn list_assets(ctx: Context, offline: bool) -> Result<()> {
|
||||
let query = AssetQuery {
|
||||
is_offline: if offline { Some(true) } else { None },
|
||||
with_exif: true,
|
||||
};
|
||||
|
||||
let mut assets: Vec<_> = fetch_all_assets(query, client)
|
||||
let mut assets: Vec<_> = fetch_all_assets(query, &ctx.client)
|
||||
.await?
|
||||
.into_iter()
|
||||
.map(|asset| Asset {
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use crate::{utils::people::fetch_all_contacts, Client};
|
||||
use crate::{context::Context, utils::people::fetch_all_contacts};
|
||||
use color_eyre::eyre::Result;
|
||||
use log::*;
|
||||
|
||||
pub async fn missing_date_of_birth(client: &Client) -> Result<()> {
|
||||
let contacts = fetch_all_contacts(client).await?;
|
||||
pub async fn missing_date_of_birth(ctx: Context) -> Result<()> {
|
||||
let contacts = fetch_all_contacts(&ctx.client).await?;
|
||||
let mut filtered_contacts = contacts
|
||||
.iter()
|
||||
.filter(|c| c.birth_date.is_none() && !c.name.is_empty())
|
||||
|
|
|
@ -8,7 +8,7 @@ use tabled::{
|
|||
Table, Tabled,
|
||||
};
|
||||
|
||||
use crate::Client;
|
||||
use crate::context::Context;
|
||||
|
||||
#[derive(Tabled)]
|
||||
struct ServerFeature {
|
||||
|
@ -18,8 +18,8 @@ struct ServerFeature {
|
|||
enabled: bool,
|
||||
}
|
||||
|
||||
pub async fn server_features(client: &Client) -> Result<()> {
|
||||
let response = client.get_server_features().await?;
|
||||
pub async fn server_features(ctx: Context) -> Result<()> {
|
||||
let response = ctx.client.get_server_features().await?;
|
||||
let mut features = vec![
|
||||
ServerFeature {
|
||||
name: "Configuration file",
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use color_eyre::eyre::Result;
|
||||
|
||||
use crate::Client;
|
||||
use crate::context::Context;
|
||||
|
||||
pub async fn server_version(client: &Client) -> Result<()> {
|
||||
let version = client.get_server_version().await?;
|
||||
pub async fn server_version(ctx: Context) -> Result<()> {
|
||||
let version = ctx.client.get_server_version().await?;
|
||||
println!("{}.{}.{}", version.major, version.minor, version.patch);
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -10,17 +10,14 @@ use vcard4::{
|
|||
};
|
||||
|
||||
use crate::{
|
||||
context::Context,
|
||||
types::{PersonResponseDto, PersonUpdateDto},
|
||||
utils::people::fetch_all_contacts,
|
||||
Client,
|
||||
};
|
||||
|
||||
pub async fn sync_date_of_birth(
|
||||
client: &Client,
|
||||
vcard_file: &PathBuf,
|
||||
dry_run: bool,
|
||||
) -> Result<()> {
|
||||
let server_contacts = fetch_all_contacts(client).await?;
|
||||
pub async fn sync_date_of_birth(ctx: Context, vcard_file: &PathBuf) -> Result<()> {
|
||||
let server_contacts = fetch_all_contacts(&ctx.client).await?;
|
||||
|
||||
let filtered_contacts: Vec<_> = server_contacts
|
||||
.iter()
|
||||
|
@ -55,7 +52,7 @@ pub async fn sync_date_of_birth(
|
|||
formatted_name
|
||||
);
|
||||
} else if bday.year() > 0 {
|
||||
update_person_bday(c, bday, client, dry_run).await?;
|
||||
update_person_bday(c, bday, &ctx.client, ctx.dry_run).await?;
|
||||
updated_dobs += 1;
|
||||
} else {
|
||||
debug!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue