hop-cli 0.2.61

Interact with Hop in your terminal
Documentation
use anyhow::{ensure, Result};
use clap::Parser;

use super::utils::format_users;
use crate::state::State;

#[derive(Debug, Parser)]
#[clap(about = "List all authenticated users")]
#[group(skip)]
pub struct Options {
    #[clap(short, long, help = "Only print the IDs of the authorized users")]
    pub quiet: bool,
}

pub fn handle(options: &Options, state: &State) -> Result<()> {
    let users = state.auth.authorized.keys().collect::<Vec<_>>();

    ensure!(!users.is_empty(), "There are no authorized users");

    if options.quiet {
        let ids = users
            .iter()
            .map(|d| d.as_str())
            .collect::<Vec<_>>()
            .join(" ");

        println!("{ids}");
    } else {
        let users_fmt = format_users(&users, true);

        println!("{}", users_fmt.join("\n"));
    }

    Ok(())
}