use crate::sshcfg;
use colored::Colorize;
#[derive(clap::Args)]
pub struct Args {
#[arg(short, long)]
pub verbose: bool,
}
pub fn run(args: Args) {
let hosts = sshcfg::list_hosts();
if hosts.is_empty() {
println!(
"{}",
"No hosts in ~/.ssh/config yet. Run `essh` and press `n` to add one.".dimmed()
);
return;
}
if args.verbose {
let width = hosts.iter().map(|h| h.alias.len()).max().unwrap_or(0);
for h in &hosts {
let key = match &h.identity {
Some(i) => format!(" ({i})"),
None => String::new(),
};
println!(" {:width$} {}{}", h.alias.bold(), h.target().dimmed(), key.dimmed());
}
} else {
for h in &hosts {
println!("{}", h.alias);
}
}
}