aboutsummaryrefslogtreecommitdiffstats
path: root/mumctl/src/main.rs
diff options
context:
space:
mode:
authorEskil Queseth <eskilq@kth.se>2020-10-31 02:27:26 +0100
committerEskil Queseth <eskilq@kth.se>2020-10-31 02:27:26 +0100
commit11c823701b12f10933b40044a12cc4048ccf8bd2 (patch)
treeb3d0b6c844383f8a45cd5081459928b75136ab95 /mumctl/src/main.rs
parent8fb4edd72dfcb2b71e91eedc5861360101374967 (diff)
downloadmum-11c823701b12f10933b40044a12cc4048ccf8bd2.tar.gz
add support for mumctl server list
Diffstat (limited to 'mumctl/src/main.rs')
-rw-r--r--mumctl/src/main.rs36
1 files changed, 34 insertions, 2 deletions
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<mumlib::
let host = matches.value_of("host").unwrap();
let username = matches.value_of("username");
let port = match matches.value_of("port").map(|e| e.parse()) {
- None => Some(64738),
+ None => Some(mumlib::DEFAULT_PORT),
Some(Err(_)) => None,
Some(Ok(v)) => Some(v),
};