Skip to main content

jira_cli/commands/
users.rs

1use crate::api::{ApiError, JiraClient};
2use crate::output::OutputConfig;
3
4/// Search for users matching a name or email fragment.
5pub async fn search(client: &JiraClient, out: &OutputConfig, query: &str) -> Result<(), ApiError> {
6    let users = client.search_users(query).await?;
7
8    if out.json {
9        out.print_data(
10            &serde_json::to_string_pretty(&serde_json::json!({
11                "total": users.len(),
12                "users": users.iter().map(|u| serde_json::json!({
13                    "accountId": u.account_id,
14                    "displayName": u.display_name,
15                    "email": u.email_address,
16                })).collect::<Vec<_>>(),
17            }))
18            .expect("failed to serialize JSON"),
19        );
20        return Ok(());
21    }
22
23    if users.is_empty() {
24        out.print_message(&format!("No users found matching '{query}'."));
25        return Ok(());
26    }
27
28    for u in &users {
29        let email = u.email_address.as_deref().unwrap_or("-");
30        println!("{:<20} {:<30} {}", u.account_id, u.display_name, email);
31    }
32    Ok(())
33}