Skip to content

Commit ec936db

Browse files
committed
chore: apply cargo fmt and clippy fixes, verify build
Phase 4: Run cargo fmt for consistent formatting, fix clippy collapsible_if warnings, verify cargo build --release succeeds and binary runs correctly with --help.
1 parent 6fae0aa commit ec936db

10 files changed

Lines changed: 97 additions & 97 deletions

File tree

src/commands/claims.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::config::resolve_connection;
99
use crate::firebase::{AuthBackend, init_firebase};
1010
use crate::output::{render_json_value, render_message, render_table};
1111
use crate::prompt::{confirm, resolve_email, resolve_string};
12-
use crate::{Cli, ClaimsCommand};
12+
use crate::{ClaimsCommand, Cli};
1313

1414
pub async fn run(cli: &Cli, command: &ClaimsCommand) -> Result<()> {
1515
match command {
@@ -28,10 +28,10 @@ pub async fn run(cli: &Cli, command: &ClaimsCommand) -> Result<()> {
2828
}
2929

3030
fn parse_claim_value(raw: &str) -> Value {
31-
if raw.starts_with('{') || raw.starts_with('[') {
32-
if let Ok(v) = serde_json::from_str(raw) {
33-
return v;
34-
}
31+
if (raw.starts_with('{') || raw.starts_with('['))
32+
&& let Ok(v) = serde_json::from_str(raw)
33+
{
34+
return v;
3535
}
3636
if raw == "true" {
3737
return Value::Bool(true);
@@ -42,10 +42,10 @@ fn parse_claim_value(raw: &str) -> Value {
4242
if let Ok(i) = raw.parse::<i64>() {
4343
return Value::Number(i.into());
4444
}
45-
if let Ok(f) = raw.parse::<f64>() {
46-
if let Some(n) = serde_json::Number::from_f64(f) {
47-
return Value::Number(n);
48-
}
45+
if let Ok(f) = raw.parse::<f64>()
46+
&& let Some(n) = serde_json::Number::from_f64(f)
47+
{
48+
return Value::Number(n);
4949
}
5050
Value::String(raw.to_string())
5151
}
@@ -181,10 +181,7 @@ async fn remove(cli: &Cli, key: Option<String>, email: Option<String>) -> Result
181181
async fn clear(cli: &Cli, email: Option<String>) -> Result<()> {
182182
let email = resolve_email(email)?;
183183

184-
if !confirm(
185-
&format!("Clear ALL custom claims for {email}?"),
186-
cli.yes,
187-
)? {
184+
if !confirm(&format!("Clear ALL custom claims for {email}?"), cli.yes)? {
188185
bail!("Aborted");
189186
}
190187

src/commands/config_cmd.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use anyhow::{Result, bail};
22

33
use crate::config::{
4-
Profile, add_profile, config_dir, load_config, remove_profile, save_config,
5-
set_default, resolve_connection,
4+
Profile, add_profile, config_dir, load_config, remove_profile, resolve_connection, save_config,
5+
set_default,
66
};
77
use crate::output::{render_message, render_single_record, render_table};
88
use crate::prompt::{resolve_select, resolve_string};
@@ -73,10 +73,8 @@ async fn init(_cli: &Cli) -> Result<()> {
7373
let mut config = load_config()?;
7474
add_profile(&mut config, name.clone(), profile);
7575

76-
let make_default = crate::prompt::confirm(
77-
&format!("Set '{name}' as the default profile?"),
78-
false,
79-
)?;
76+
let make_default =
77+
crate::prompt::confirm(&format!("Set '{name}' as the default profile?"), false)?;
8078
if make_default {
8179
config.default_profile = Some(name.clone());
8280
}
@@ -202,15 +200,24 @@ async fn show(cli: &Cli, name: Option<String>) -> Result<()> {
202200
("default", is_default.to_string()),
203201
(
204202
"project",
205-
profile.project.clone().unwrap_or_else(|| "(not set)".to_string()),
203+
profile
204+
.project
205+
.clone()
206+
.unwrap_or_else(|| "(not set)".to_string()),
206207
),
207208
(
208209
"credentials",
209-
profile.credentials.clone().unwrap_or_else(|| "(not set)".to_string()),
210+
profile
211+
.credentials
212+
.clone()
213+
.unwrap_or_else(|| "(not set)".to_string()),
210214
),
211215
(
212216
"emulator_host",
213-
profile.emulator_host.clone().unwrap_or_else(|| "(not set)".to_string()),
217+
profile
218+
.emulator_host
219+
.clone()
220+
.unwrap_or_else(|| "(not set)".to_string()),
214221
),
215222
],
216223
);
@@ -231,8 +238,7 @@ async fn which(cli: &Cli) -> Result<()> {
231238
&[
232239
(
233240
"profile",
234-
conn.profile_name
235-
.unwrap_or_else(|| "(none)".to_string()),
241+
conn.profile_name.unwrap_or_else(|| "(none)".to_string()),
236242
),
237243
(
238244
"source",
@@ -241,18 +247,15 @@ async fn which(cli: &Cli) -> Result<()> {
241247
),
242248
(
243249
"project",
244-
conn.project
245-
.unwrap_or_else(|| "(auto-detect)".to_string()),
250+
conn.project.unwrap_or_else(|| "(auto-detect)".to_string()),
246251
),
247252
(
248253
"credentials",
249-
conn.credentials
250-
.unwrap_or_else(|| "(ADC)".to_string()),
254+
conn.credentials.unwrap_or_else(|| "(ADC)".to_string()),
251255
),
252256
(
253257
"emulator",
254-
conn.emulator_host
255-
.unwrap_or_else(|| "no".to_string()),
258+
conn.emulator_host.unwrap_or_else(|| "no".to_string()),
256259
),
257260
],
258261
);

src/commands/info.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
use anyhow::Result;
22
use rs_firebase_admin_sdk::auth::FirebaseAuthService;
33

4+
use crate::Cli;
45
use crate::config::resolve_connection;
56
use crate::errors::IntoAnyhow;
67
use crate::firebase::{AuthBackend, init_firebase};
78
use crate::output::{render_message, render_single_record};
8-
use crate::Cli;
99

1010
pub async fn run(cli: &Cli) -> Result<()> {
1111
let conn = resolve_connection(

src/commands/links.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use anyhow::Result;
2-
use rs_firebase_admin_sdk::auth::oob_code::{OobCodeAction, OobCodeActionType};
32
use rs_firebase_admin_sdk::auth::FirebaseAuthService;
3+
use rs_firebase_admin_sdk::auth::oob_code::{OobCodeAction, OobCodeActionType};
44

55
use crate::config::resolve_connection;
66
use crate::errors::IntoAnyhow;

src/commands/users.rs

Lines changed: 19 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ pub async fn run(cli: &Cli, command: &UsersCommand) -> Result<()> {
3737

3838
async fn build_auth(
3939
cli: &Cli,
40-
) -> Result<rs_firebase_admin_sdk::auth::FirebaseAuth<rs_firebase_admin_sdk::client::ReqwestApiClient>>
41-
{
40+
) -> Result<
41+
rs_firebase_admin_sdk::auth::FirebaseAuth<rs_firebase_admin_sdk::client::ReqwestApiClient>,
42+
> {
4243
let conn = resolve_connection(
4344
&cli.profile,
4445
&cli.project,
@@ -85,7 +86,9 @@ fn format_claims(user: &User) -> String {
8586
}
8687

8788
async fn lookup_user_by_email(
88-
auth: &rs_firebase_admin_sdk::auth::FirebaseAuth<rs_firebase_admin_sdk::client::ReqwestApiClient>,
89+
auth: &rs_firebase_admin_sdk::auth::FirebaseAuth<
90+
rs_firebase_admin_sdk::client::ReqwestApiClient,
91+
>,
8992
email: &str,
9093
) -> Result<User> {
9194
let ids = UserIdentifiers::builder()
@@ -180,8 +183,7 @@ async fn create(
180183
("Email", user.email.unwrap_or(email)),
181184
(
182185
"Display Name",
183-
user.display_name
184-
.unwrap_or_else(|| "N/A".to_string()),
186+
user.display_name.unwrap_or_else(|| "N/A".to_string()),
185187
),
186188
];
187189
if auto_generated {
@@ -202,9 +204,7 @@ async fn disable(cli: &Cli, email: Option<String>) -> Result<()> {
202204
return Ok(());
203205
}
204206

205-
let update = UserUpdate::builder(user.uid)
206-
.disabled(true)
207-
.build();
207+
let update = UserUpdate::builder(user.uid).disabled(true).build();
208208
auth.update_user(update).await.into_anyhow()?;
209209

210210
render_message(&format!("User {email} has been disabled."));
@@ -216,9 +216,7 @@ async fn enable(cli: &Cli, email: Option<String>) -> Result<()> {
216216
let email = resolve_email(email)?;
217217
let user = lookup_user_by_email(&auth, &email).await?;
218218

219-
let update = UserUpdate::builder(user.uid)
220-
.disabled(false)
221-
.build();
219+
let update = UserUpdate::builder(user.uid).disabled(false).build();
222220
auth.update_user(update).await.into_anyhow()?;
223221

224222
render_message(&format!("User {email} has been enabled."));
@@ -275,9 +273,7 @@ async fn remove(cli: &Cli, csv_path: Option<String>) -> Result<()> {
275273
let mut resolved = Vec::with_capacity(values.len());
276274
let mut not_found: Vec<String> = Vec::new();
277275
for email in &values {
278-
let ids = UserIdentifiers::builder()
279-
.with_email(email.clone())
280-
.build();
276+
let ids = UserIdentifiers::builder().with_email(email.clone()).build();
281277
match auth.get_user(ids).await.into_anyhow()? {
282278
Some(user) => resolved.push(user.uid),
283279
None => not_found.push(email.clone()),
@@ -290,7 +286,12 @@ async fn remove(cli: &Cli, csv_path: Option<String>) -> Result<()> {
290286
eprintln!(
291287
"Warning: {} email(s) not found and will be skipped: {}",
292288
not_found.len(),
293-
not_found.iter().take(5).cloned().collect::<Vec<_>>().join(", ")
289+
not_found
290+
.iter()
291+
.take(5)
292+
.cloned()
293+
.collect::<Vec<_>>()
294+
.join(", ")
294295
);
295296
if not_found.len() > 5 {
296297
eprintln!(" ... and {} more", not_found.len() - 5);
@@ -404,9 +405,8 @@ async fn list_inactive(cli: &Cli, days: u64) -> Result<()> {
404405
.as_millis() as i64
405406
- (days as i64 * 86_400 * 1000);
406407

407-
let threshold_dt =
408-
OffsetDateTime::from_unix_timestamp_nanos(threshold_ms as i128 * 1_000_000)
409-
.map_err(|e| anyhow!("Invalid threshold timestamp: {e}"))?;
408+
let threshold_dt = OffsetDateTime::from_unix_timestamp_nanos(threshold_ms as i128 * 1_000_000)
409+
.map_err(|e| anyhow!("Invalid threshold timestamp: {e}"))?;
410410

411411
let spinner = ProgressBar::new_spinner();
412412
spinner.set_style(
@@ -446,10 +446,7 @@ async fn list_inactive(cli: &Cli, days: u64) -> Result<()> {
446446
]);
447447
}
448448
}
449-
spinner.set_message(format!(
450-
"scanned {scanned}, found {} inactive",
451-
rows.len()
452-
));
449+
spinner.set_message(format!("scanned {scanned}, found {} inactive", rows.len()));
453450
page = Some(user_list);
454451
}
455452
None => break,

src/config.rs

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ pub fn resolve_profile_name(
105105
return Ok(Some(env_profile));
106106
}
107107

108-
if let Some(ref default) = config.default_profile {
109-
if config.profiles.contains_key(default) {
110-
return Ok(Some(default.clone()));
111-
}
108+
if let Some(ref default) = config.default_profile
109+
&& config.profiles.contains_key(default)
110+
{
111+
return Ok(Some(default.clone()));
112112
}
113113

114114
Ok(None)
@@ -137,21 +137,15 @@ pub fn resolve_connection(
137137
(Profile::default(), None)
138138
};
139139

140-
let emulator_host = cli_emulator_host
141-
.clone()
142-
.or(profile.emulator_host);
143-
144-
let project = cli_project
145-
.clone()
146-
.or(profile.project);
147-
148-
let credentials = cli_credentials
149-
.clone()
150-
.or_else(|| {
151-
profile
152-
.credentials
153-
.map(|c| shellexpand::tilde(&c).to_string())
154-
});
140+
let emulator_host = cli_emulator_host.clone().or(profile.emulator_host);
141+
142+
let project = cli_project.clone().or(profile.project);
143+
144+
let credentials = cli_credentials.clone().or_else(|| {
145+
profile
146+
.credentials
147+
.map(|c| shellexpand::tilde(&c).to_string())
148+
});
155149

156150
Ok(ResolvedConnection {
157151
profile_name,

src/firebase.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
use anyhow::{Context, Result, anyhow, bail};
2-
use rs_firebase_admin_sdk::{
3-
App,
4-
auth::FirebaseAuth,
5-
client::ReqwestApiClient,
6-
};
2+
use rs_firebase_admin_sdk::{App, auth::FirebaseAuth, client::ReqwestApiClient};
73

84
use crate::config::ResolvedConnection;
95

106
pub enum AuthBackend {
11-
Emulator { host: String },
7+
Emulator {
8+
host: String,
9+
},
1210
Live {
1311
credentials_path: Option<String>,
1412
project_id: Option<String>,
@@ -54,9 +52,7 @@ pub async fn init_firebase(backend: AuthBackend) -> Result<FirebaseAuth<ReqwestA
5452
.or_else(|| sa_json["project_id"].as_str().map(String::from))
5553
.ok_or_else(|| anyhow!("project_id required when not in service account JSON"))?;
5654

57-
use google_cloud_auth::credentials::service_account::{
58-
self, AccessSpecifier,
59-
};
55+
use google_cloud_auth::credentials::service_account::{self, AccessSpecifier};
6056
use rs_firebase_admin_sdk::Credentials;
6157

6258
let scopes = [

src/main.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,23 @@ use clap::{ArgAction, Parser, Subcommand, ValueEnum};
1212
#[derive(Parser)]
1313
#[command(name = "fbadmin", version, about = "Firebase Auth administration CLI")]
1414
pub struct Cli {
15-
#[arg(long, short = 'p', env = "FBADMIN_PROFILE", help = "Use a named profile from config")]
15+
#[arg(
16+
long,
17+
short = 'p',
18+
env = "FBADMIN_PROFILE",
19+
help = "Use a named profile from config"
20+
)]
1621
pub profile: Option<String>,
1722

1823
#[arg(long, env = "FBADMIN_PROJECT", help = "Firebase project ID (uses ADC)")]
1924
pub project: Option<String>,
2025

21-
#[arg(long, short = 'c', env = "FBADMIN_CREDENTIALS", help = "Path to service account JSON")]
26+
#[arg(
27+
long,
28+
short = 'c',
29+
env = "FBADMIN_CREDENTIALS",
30+
help = "Path to service account JSON"
31+
)]
2232
pub credentials: Option<String>,
2333

2434
#[arg(

src/output.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,12 @@ pub fn render_single_record(format: &OutputFormat, fields: &[(&str, String)]) {
88
OutputFormat::Table => {
99
let max_key = fields.iter().map(|(k, _)| k.len()).max().unwrap_or(0);
1010
for (key, value) in fields {
11-
println!(" {:<width$} {}", format!("{key}:"), value, width = max_key + 1);
11+
println!(
12+
" {:<width$} {}",
13+
format!("{key}:"),
14+
value,
15+
width = max_key + 1
16+
);
1217
}
1318
}
1419
OutputFormat::Json => {
@@ -19,7 +24,9 @@ pub fn render_single_record(format: &OutputFormat, fields: &[(&str, String)]) {
1924
println!("{}", serde_json::to_string(&Value::Object(map)).unwrap());
2025
}
2126
OutputFormat::Csv => {
22-
eprintln!("Warning: --format csv is not applicable to single records, using table format");
27+
eprintln!(
28+
"Warning: --format csv is not applicable to single records, using table format"
29+
);
2330
render_single_record(&OutputFormat::Table, fields);
2431
}
2532
}

0 commit comments

Comments
 (0)