From 11c823701b12f10933b40044a12cc4048ccf8bd2 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Sat, 31 Oct 2020 02:27:26 +0100 Subject: add support for mumctl server list --- mumctl/src/main.rs | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'mumctl') diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs index 9471b6a..18967db 100644 --- a/mumctl/src/main.rs +++ b/mumctl/src/main.rs @@ -23,6 +23,11 @@ fn main() { setup_logger(io::stderr(), true); let mut config = config::read_default_cfg(); + /*println!("{:?}", send_command(Command::ServerStatus { + host: "icahasse.se".to_string(), + port: 64738, + }).unwrap());*/ + let mut app = App::new("mumctl") .setting(AppSettings::ArgRequiredElseHelp) .subcommand( @@ -74,7 +79,8 @@ fn main() { ) .subcommand( SubCommand::with_name("remove").arg(Arg::with_name("name").required(true)), - ), + ) + .subcommand(SubCommand::with_name("list")), ) .subcommand( SubCommand::with_name("channel") @@ -116,6 +122,32 @@ fn main() { match_server_remove(matches, &mut config); } else if let Some(matches) = matches.subcommand_matches("add") { match_server_add(matches, &mut config); + } else if let Some(_) = matches.subcommand_matches("list") { + let servers = config + .as_ref() + .map(|e| e.servers + .as_ref() + .map(|e| e.clone()) + .unwrap_or(Vec::new())) + .unwrap_or(Vec::new()); + for (server, response) in servers + .into_iter() + .map(|e| { + let response = send_command(Command::ServerStatus { + host: e.host.clone(), + port: e.port.unwrap_or(mumlib::DEFAULT_PORT), + }); + (e, response) + }) + .filter(|e| e.1.is_ok()) + .map(|e| (e.0, e.1.unwrap().unwrap())) + { + if let CommandResponse::ServerStatus { users, max_users, .. } = response { + println!("{} [{}/{}]", server.name, users, max_users) + } else { + unreachable!() + } + } } } else if let Some(matches) = matches.subcommand_matches("channel") { if let Some(_matches) = matches.subcommand_matches("list") { @@ -195,7 +227,7 @@ fn match_server_connect(matches: &clap::ArgMatches<'_>, config: &Option Some(64738), + None => Some(mumlib::DEFAULT_PORT), Some(Err(_)) => None, Some(Ok(v)) => Some(v), }; -- cgit v1.2.1