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 From d72b0fe5862a99d9ce1a0ef37938f4517de36ed7 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Sat, 31 Oct 2020 02:37:24 +0100 Subject: cargo fmt --- mumctl/src/main.rs | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'mumctl') diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs index 18967db..50ccfe0 100644 --- a/mumctl/src/main.rs +++ b/mumctl/src/main.rs @@ -23,11 +23,6 @@ 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( @@ -125,10 +120,7 @@ fn main() { } 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())) + .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() @@ -142,7 +134,10 @@ fn main() { .filter(|e| e.1.is_ok()) .map(|e| (e.0, e.1.unwrap().unwrap())) { - if let CommandResponse::ServerStatus { users, max_users, .. } = response { + if let CommandResponse::ServerStatus { + users, max_users, .. + } = response + { println!("{} [{}/{}]", server.name, users, max_users) } else { unreachable!() -- cgit v1.2.1 From f169a04da325b6467335812a53b315f1ecc8c7ad Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Mon, 2 Nov 2020 23:40:50 +0100 Subject: add warning without config --- mumctl/src/main.rs | 3 +++ 1 file changed, 3 insertions(+) (limited to 'mumctl') diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs index 50ccfe0..9d38aa0 100644 --- a/mumctl/src/main.rs +++ b/mumctl/src/main.rs @@ -122,6 +122,9 @@ fn main() { .as_ref() .map(|e| e.servers.as_ref().map(|e| e.clone()).unwrap_or(Vec::new())) .unwrap_or(Vec::new()); + if servers.len() == 0 { + println!("{} No servers in config", "warning:".yellow()); + } for (server, response) in servers .into_iter() .map(|e| { -- cgit v1.2.1