sesame/
status.rs

1use core_types::{EventKind, SecurityLevel};
2use owo_colors::OwoColorize;
3
4use crate::ipc::{connect, rpc};
5
6pub(crate) async fn cmd_status() -> anyhow::Result<()> {
7    let client = connect().await?;
8
9    match rpc(&client, EventKind::StatusRequest, SecurityLevel::Internal).await? {
10        EventKind::StatusResponse {
11            active_profiles,
12            default_profile,
13            locked,
14            lock_state,
15            ..
16        } => {
17            // Per-profile lock state display.
18            if lock_state.is_empty() {
19                // Fallback: daemon didn't return per-profile state, use global locked flag.
20                let lock_status = if locked {
21                    "locked".red().bold().to_string()
22                } else {
23                    "unlocked".green().bold().to_string()
24                };
25                println!("Secrets daemon: {lock_status}");
26            } else {
27                println!("Vaults:");
28                let max_name_len = lock_state
29                    .keys()
30                    .map(|k| k.as_ref().len())
31                    .max()
32                    .unwrap_or(0);
33                for (profile, is_locked) in &lock_state {
34                    let status = if *is_locked {
35                        "locked".red().bold().to_string()
36                    } else {
37                        "unlocked".green().bold().to_string()
38                    };
39                    println!(
40                        "  {:width$}  {status}",
41                        profile.as_ref(),
42                        width = max_name_len
43                    );
44                }
45            }
46
47            println!("Default profile: {}", default_profile.as_ref().bold());
48
49            if active_profiles.is_empty() {
50                println!("Active profiles: {}", "none".dimmed());
51            } else {
52                println!("Active profiles:");
53                for p in &active_profiles {
54                    let marker = if p == &default_profile {
55                        " (default)"
56                    } else {
57                        ""
58                    };
59                    println!("  - {p}{marker}");
60                }
61            }
62        }
63        other => anyhow::bail!("unexpected response: {other:?}"),
64    }
65
66    Ok(())
67}