diff --git a/src/bin/force_profile_country.rs b/src/bin/force_profile_country.rs index 1062901..1526949 100644 --- a/src/bin/force_profile_country.rs +++ b/src/bin/force_profile_country.rs @@ -2,7 +2,7 @@ extern crate nederlandskie; use std::env; -use anyhow::{anyhow, Context, Result}; +use anyhow::{anyhow, bail, Context, Result}; use clap::Parser; use dotenv::dotenv; @@ -11,9 +11,13 @@ use nederlandskie::services::{Bluesky, Database}; #[derive(Parser, Debug)] struct Args { /// Handles of the users to force the country for, comma-separated - #[arg(long, required(true), value_delimiter(','))] + #[arg(long, value_delimiter(','))] handle: Vec, + /// DIDs of the users to force the country for, comma-separated + #[arg(long, value_delimiter(','))] + did: Vec, + /// Country to use, two letters #[arg(long)] country: String, @@ -25,6 +29,10 @@ async fn main() -> Result<()> { let args = Args::parse(); + if args.handle.is_empty() && args.did.is_empty() { + bail!("Either --handle or --did must be supplied"); + } + let database_url = env::var("DATABASE_URL").context("DATABASE_URL environment variable must be set")?; @@ -47,5 +55,14 @@ async fn main() -> Result<()> { ); } + for did in &args.did { + database.force_profile_country(&did, &args.country).await?; + + println!( + "Stored '{}' as the country for profile with did '{}'", + args.country, did + ); + } + Ok(()) }