everruns-cli 0.53.0

Command-line interface for Everruns — run and manage agents from your terminal
// CLI status command — show current user and org

use anyhow::Result;

use crate::auth::{CredentialStore, credentials_path};

pub fn run(profile: &str) -> Result<()> {
    let store = CredentialStore::load().unwrap_or_default();

    let profile_name = if profile.is_empty() {
        if store.current_profile.is_empty() {
            "default"
        } else {
            &store.current_profile
        }
    } else {
        profile
    };

    if let Some(p) = store.profiles.get(profile_name) {
        crate::ui::field("Profile", profile_name);
        crate::ui::field("API URL", &p.api_url);
        crate::ui::field(
            "API Key",
            format!(
                "{}...{}",
                &p.api_key[..std::cmp::min(12, p.api_key.len())],
                if p.api_key.len() > 16 {
                    &p.api_key[p.api_key.len() - 4..]
                } else {
                    ""
                }
            ),
        );
        if let Some(email) = &p.user_email {
            crate::ui::field(
                "User",
                format!("{} ({})", p.user_name.as_deref().unwrap_or(""), email),
            );
        }
        if let Some(org_id) = &p.org_id {
            crate::ui::field("Org", org_id);
        }
    } else {
        let path_hint = credentials_path()
            .map(|p| {
                let display = if let Some(home) = crate::user_dirs::home_dir() {
                    if let Ok(rel) = p.strip_prefix(&home) {
                        format!("~/{}", rel.display())
                    } else {
                        p.display().to_string()
                    }
                } else {
                    p.display().to_string()
                };
                format!(" (looked in {})", display)
            })
            .unwrap_or_default();
        crate::ui::fail(format!(
            "Not logged in. Run {} to authenticate.{}",
            crate::ui::cmd("everruns login"),
            crate::ui::dim(path_hint)
        ));
        std::process::exit(1);
    }

    Ok(())
}