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 0cb39d13bba3dc5ffa3231e6021066e4191a43a4 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Mon, 2 Nov 2020 21:47:47 +0100 Subject: refactor and add audio out config command --- mumctl/src/main.rs | 109 +++++++++++++++++++++-------------------------------- 1 file changed, 42 insertions(+), 67 deletions(-) (limited to 'mumctl') diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs index 9471b6a..162616c 100644 --- a/mumctl/src/main.rs +++ b/mumctl/src/main.rs @@ -150,6 +150,13 @@ fn main() { "audio.input_volume" => { if let Ok(volume) = value.parse() { send_command(Command::InputVolumeSet(volume)).unwrap(); + config.audio.input_volume = Some(volume); + } + } + "audio.output_volume" => { + if let Ok(volume) = value.parse() { + send_command(Command::InputVolumeSet(volume)).unwrap(); + config.audio.output_volume = Some(volume); } } _ => { @@ -171,27 +178,25 @@ fn main() { return; }; - if let Some(config) = config { - if !config::cfg_exists() { - println!( - "Config file not found. Create one in {}? [Y/n]", - config::get_creatable_cfg_path() - ); - let stdin = std::io::stdin(); - let response = stdin.lock().lines().next(); - match response.map(|e| e.map(|e| &e == "Y")) { - Some(Ok(true)) => { - config.write_default_cfg(true).unwrap(); - } - _ => {} + if !config::cfg_exists() { + println!( + "Config file not found. Create one in {}? [Y/n]", + config::get_creatable_cfg_path() + ); + let stdin = std::io::stdin(); + let response = stdin.lock().lines().next(); + match response.map(|e| e.map(|e| &e == "Y")) { + Some(Ok(true)) => { + config.write_default_cfg(true).unwrap(); } - } else { - config.write_default_cfg(false).unwrap(); + _ => {} } + } else { + config.write_default_cfg(false).unwrap(); } } -fn match_server_connect(matches: &clap::ArgMatches<'_>, config: &Option) { +fn match_server_connect(matches: &clap::ArgMatches<'_>, config: &mumlib::config::Config) { let host = matches.value_of("host").unwrap(); let username = matches.value_of("username"); let port = match matches.value_of("port").map(|e| e.parse()) { @@ -200,41 +205,35 @@ fn match_server_connect(matches: &clap::ArgMatches<'_>, config: &Option Some(v), }; if let Some(port) = port { - let response = match config.as_ref().and_then(|e| { - e.servers - .as_ref() - .and_then(|e| e.iter().find(|e| e.name == host)) - }) { - Some(config) => { - let host = config.host.as_str(); - let port = config.port.unwrap_or(port); - let username = config.username.as_ref().map(|e| e.as_str()).or(username); + let (host, port, username) = match config.servers + .as_ref() + .and_then(|e| e.iter() + .find(|e| e.name == host)) + { + Some(server_config) => { + let host = server_config.host.as_str(); + let port = server_config.port.unwrap_or(port); + let username = server_config.username.as_ref().map(|e| e.as_str()).or(username); if username.is_none() { println!("{} no username specified", "error:".red()); return; } - send_command(Command::ServerConnect { - host: host.to_string(), - port, - username: username.unwrap().to_string(), - accept_invalid_cert: true, //TODO - }) - .map(|e| (e, host)) + (host, port, username.unwrap()) } None => { if username.is_none() { println!("{} no username specified", "error:".red()); return; } - send_command(Command::ServerConnect { - host: host.to_string(), - port, - username: username.unwrap().to_string(), - accept_invalid_cert: true, //TODO - }) - .map(|e| (e, host)) + (host, port, username.unwrap()) } }; + let response = send_command(Command::ServerConnect { + host: host.to_string(), + port, + username: username.to_string(), + accept_invalid_cert: true, //TODO + }).map(|e| (e, host)); match response { Ok((e, host)) => { if let Some(CommandResponse::ServerConnect { welcome_message }) = e { @@ -253,14 +252,8 @@ fn match_server_connect(matches: &clap::ArgMatches<'_>, config: &Option, - config: &mut Option, + config: &mut mumlib::config::Config, ) { - if config.is_none() { - *config = Some(mumlib::config::Config::default()); - } - - let config = config.as_mut().unwrap(); - if let Some(server_name) = matches.value_of("server_name") { if let Some(servers) = &mut config.servers { let server = servers.iter_mut().find(|s| s.name == server_name); @@ -365,14 +358,8 @@ fn match_server_config( fn match_server_rename( matches: &clap::ArgMatches<'_>, - config: &mut Option, + config: &mut mumlib::config::Config, ) { - if config.is_none() { - *config = Some(mumlib::config::Config::default()); - } - - let config = config.as_mut().unwrap(); - if let Some(servers) = &mut config.servers { let prev_name = matches.value_of("prev_name").unwrap(); let next_name = matches.value_of("next_name").unwrap(); @@ -386,14 +373,8 @@ fn match_server_rename( fn match_server_remove( matches: &clap::ArgMatches<'_>, - config: &mut Option, + config: &mut mumlib::config::Config, ) { - if config.is_none() { - *config = Some(mumlib::config::Config::default()); - } - - let config = config.as_mut().unwrap(); - let name = matches.value_of("name").unwrap(); if let Some(servers) = &mut config.servers { match servers.iter().position(|server| server.name == name) { @@ -409,13 +390,7 @@ fn match_server_remove( } } -fn match_server_add(matches: &clap::ArgMatches<'_>, config: &mut Option) { - if config.is_none() { - *config = Some(mumlib::config::Config::default()); - } - - let mut config = config.as_mut().unwrap(); - +fn match_server_add(matches: &clap::ArgMatches<'_>, config: &mut mumlib::config::Config) { let name = matches.value_of("name").unwrap().to_string(); let host = matches.value_of("host").unwrap().to_string(); // optional arguments map None to None -- cgit v1.2.1 From 96f77c16ba006955acede513c310f95cf8efa5e7 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Mon, 2 Nov 2020 22:13:59 +0100 Subject: fix minor oopsie --- mumctl/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'mumctl') diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs index 162616c..6513d6d 100644 --- a/mumctl/src/main.rs +++ b/mumctl/src/main.rs @@ -155,7 +155,7 @@ fn main() { } "audio.output_volume" => { if let Ok(volume) = value.parse() { - send_command(Command::InputVolumeSet(volume)).unwrap(); + send_command(Command::OutputVolumeSet(volume)).unwrap(); config.audio.output_volume = Some(volume); } } -- cgit v1.2.1 From 00edffbe2aa8a70e69d1a467b441265bc3a0f788 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Mon, 2 Nov 2020 22:47:21 +0100 Subject: add support for changing volume of individual users --- mumctl/src/main.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'mumctl') diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs index 6513d6d..0054d17 100644 --- a/mumctl/src/main.rs +++ b/mumctl/src/main.rs @@ -99,6 +99,16 @@ fn main() { .arg(Arg::with_name("zsh").long("zsh")) .arg(Arg::with_name("bash").long("bash")) .arg(Arg::with_name("fish").long("fish")), + ) + .subcommand( + SubCommand::with_name("volume") + .subcommand( + SubCommand::with_name("set") + .arg(Arg::with_name("user").required(true)) + .arg(Arg::with_name("volume").required(true)) + ) + .arg(Arg::with_name("user").required(true)) + .setting(AppSettings::SubcommandsNegateReqs) ); let matches = app.clone().get_matches(); @@ -176,6 +186,20 @@ fn main() { &mut io::stdout(), ); return; + } else if let Some(matches) = matches.subcommand_matches("volume") { + if let Some(matches) = matches.subcommand_matches("set") { + let user = matches.value_of("user").unwrap(); + let volume = matches.value_of("volume").unwrap(); + if let Ok(val) = volume.parse() { + err_print!(send_command(Command::UserVolumeSet(user.to_string(), val))) + } else { + println!("{} Invalid volume value: {}", "error:".red(), volume); + } + } else { + let _user = matches.value_of("user").unwrap(); + //TODO implement me + //needs work on mumd to implement + } }; if !config::cfg_exists() { -- cgit v1.2.1 From 9d60f06ae05c5de08a026c7f9067c1a339bc24be Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Mon, 2 Nov 2020 22:57:52 +0100 Subject: remove redundancy --- mumctl/src/main.rs | 220 +++++++++++++++++++++++++---------------------------- 1 file changed, 105 insertions(+), 115 deletions(-) (limited to 'mumctl') diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs index 0054d17..2ceb99c 100644 --- a/mumctl/src/main.rs +++ b/mumctl/src/main.rs @@ -229,10 +229,8 @@ fn match_server_connect(matches: &clap::ArgMatches<'_>, config: &mumlib::config: Some(Ok(v)) => Some(v), }; if let Some(port) = port { - let (host, port, username) = match config.servers - .as_ref() - .and_then(|e| e.iter() - .find(|e| e.name == host)) + let (host, port, username) = match config.servers.iter() + .find(|e| e.name == host) { Some(server_config) => { let host = server_config.host.as_str(); @@ -279,102 +277,97 @@ fn match_server_config( config: &mut mumlib::config::Config, ) { if let Some(server_name) = matches.value_of("server_name") { - if let Some(servers) = &mut config.servers { - let server = servers.iter_mut().find(|s| s.name == server_name); - if let Some(server) = server { - if let Some(var_name) = matches.value_of("var_name") { - if let Some(var_value) = matches.value_of("var_value") { - // save var_value in var_name (if it is valid) + let server = config.servers.iter_mut().find(|s| s.name == server_name); + if let Some(server) = server { + if let Some(var_name) = matches.value_of("var_name") { + if let Some(var_value) = matches.value_of("var_value") { + // save var_value in var_name (if it is valid) + match var_name { + "name" => { + println!("{} use mumctl server rename instead!", "error:".red()); + } + "host" => { + server.host = var_value.to_string(); + } + "port" => { + server.port = Some(var_value.parse().unwrap()); + } + "username" => { + server.username = Some(var_value.to_string()); + } + "password" => { + server.password = Some(var_value.to_string()); //TODO ask stdin if empty + } + _ => { + println!("{} variable {} not found", "error:".red(), var_name); + } + }; + } else { + // var_value is None + // print value of var_name + println!( + "{}", match var_name { "name" => { - println!("{} use mumctl server rename instead!", "error:".red()); + server.name.to_string() } "host" => { - server.host = var_value.to_string(); + server.host.to_string() } "port" => { - server.port = Some(var_value.parse().unwrap()); + server + .port + .map(|s| s.to_string()) + .unwrap_or(format!("{} not set", "error:".red())) } "username" => { - server.username = Some(var_value.to_string()); + server + .username + .as_ref() + .map(|s| s.to_string()) + .unwrap_or(format!("{} not set", "error:".red())) } "password" => { - server.password = Some(var_value.to_string()); //TODO ask stdin if empty + server + .password + .as_ref() + .map(|s| s.to_string()) + .unwrap_or(format!("{} not set", "error:".red())) } _ => { - println!("{} variable {} not found", "error:".red(), var_name); - } - }; - } else { - // var_value is None - // print value of var_name - println!( - "{}", - match var_name { - "name" => { - server.name.to_string() - } - "host" => { - server.host.to_string() - } - "port" => { - server - .port - .map(|s| s.to_string()) - .unwrap_or(format!("{} not set", "error:".red())) - } - "username" => { - server - .username - .as_ref() - .map(|s| s.to_string()) - .unwrap_or(format!("{} not set", "error:".red())) - } - "password" => { - server - .password - .as_ref() - .map(|s| s.to_string()) - .unwrap_or(format!("{} not set", "error:".red())) - } - _ => { - format!("{} unknown variable", "error:".red()) - } + format!("{} unknown variable", "error:".red()) } - ); - } - } else { - // var_name is None - // print server config - print!( - "{}{}{}{}", - format!("host: {}\n", server.host.to_string()), - server - .port - .map(|s| format!("port: {}\n", s)) - .unwrap_or("".to_string()), - server - .username - .as_ref() - .map(|s| format!("username: {}\n", s)) - .unwrap_or("".to_string()), - server - .password - .as_ref() - .map(|s| format!("password: {}\n", s)) - .unwrap_or("".to_string()), - ) + } + ); } } else { - // server is None - println!("{} server {} not found", "error:".red(), server_name); + // var_name is None + // print server config + print!( + "{}{}{}{}", + format!("host: {}\n", server.host.to_string()), + server + .port + .map(|s| format!("port: {}\n", s)) + .unwrap_or("".to_string()), + server + .username + .as_ref() + .map(|s| format!("username: {}\n", s)) + .unwrap_or("".to_string()), + server + .password + .as_ref() + .map(|s| format!("password: {}\n", s)) + .unwrap_or("".to_string()), + ) } } else { - // servers is None - println!("{} no servers found in configuration", "error:".red()); + // server is None + println!("{} server {} not found", "error:".red(), server_name); } } else { - for server in config.servers.iter().flat_map(|e| e.iter()) { + for server in config.servers.iter() { println!("{}", server.name); } } @@ -384,15 +377,15 @@ fn match_server_rename( matches: &clap::ArgMatches<'_>, config: &mut mumlib::config::Config, ) { - if let Some(servers) = &mut config.servers { - let prev_name = matches.value_of("prev_name").unwrap(); - let next_name = matches.value_of("next_name").unwrap(); - if let Some(server) = servers.iter_mut().find(|s| s.name == prev_name) { - server.name = next_name.to_string(); - } else { - println!("{} server {} not found", "error:".red(), prev_name); - } + //if let Some(servers) = &mut config.servers { + let prev_name = matches.value_of("prev_name").unwrap(); + let next_name = matches.value_of("next_name").unwrap(); + if let Some(server) = config.servers.iter_mut().find(|s| s.name == prev_name) { + server.name = next_name.to_string(); + } else { + println!("{} server {} not found", "error:".red(), prev_name); } + //} } fn match_server_remove( @@ -400,18 +393,15 @@ fn match_server_remove( config: &mut mumlib::config::Config, ) { let name = matches.value_of("name").unwrap(); - if let Some(servers) = &mut config.servers { - match servers.iter().position(|server| server.name == name) { - Some(idx) => { - servers.remove(idx); - } - None => { - println!("{} server {} not found", "error:".red(), name); - } - }; - } else { - println!("{} no servers found in configuration", "error:".red()); - } + //if let Some(servers) = &mut config.servers { + match config.servers.iter().position(|server| server.name == name) { + Some(idx) => { + config.servers.remove(idx); + } + None => { + println!("{} server {} not found", "error:".red(), name); + } + }; } fn match_server_add(matches: &clap::ArgMatches<'_>, config: &mut mumlib::config::Config) { @@ -421,27 +411,27 @@ fn match_server_add(matches: &clap::ArgMatches<'_>, config: &mut mumlib::config: let port = matches.value_of("port").map(|s| s.parse().unwrap()); let username = matches.value_of("username").map(|s| s.to_string()); let password = matches.value_of("password").map(|s| s.to_string()); - if let Some(servers) = &mut config.servers { - if servers.iter().any(|s| s.name == name) { - println!("{} a server named {} already exists", "error:".red(), name); - } else { - servers.push(ServerConfig { - name, - host, - port, - username, - password, - }); - } + //if let Some(servers) = &mut config.servers { + if config.servers.iter().any(|s| s.name == name) { + println!("{} a server named {} already exists", "error:".red(), name); } else { - config.servers = Some(vec![ServerConfig { + config.servers.push(ServerConfig { name, host, port, username, password, - }]); + }); } + /*} else { + config.servers = vec![ServerConfig { + name, + host, + port, + username, + password, + }]; + }*/ } fn parse_status(server_state: &mumlib::state::Server) { -- cgit v1.2.1 From 36b5d69929d15212f5845f42d0239ba50e46a69c Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Mon, 2 Nov 2020 23:01:08 +0100 Subject: cargo fmt --- mumctl/src/main.rs | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) (limited to 'mumctl') diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs index 2ceb99c..005e703 100644 --- a/mumctl/src/main.rs +++ b/mumctl/src/main.rs @@ -105,10 +105,10 @@ fn main() { .subcommand( SubCommand::with_name("set") .arg(Arg::with_name("user").required(true)) - .arg(Arg::with_name("volume").required(true)) + .arg(Arg::with_name("volume").required(true)), ) .arg(Arg::with_name("user").required(true)) - .setting(AppSettings::SubcommandsNegateReqs) + .setting(AppSettings::SubcommandsNegateReqs), ); let matches = app.clone().get_matches(); @@ -229,13 +229,15 @@ fn match_server_connect(matches: &clap::ArgMatches<'_>, config: &mumlib::config: Some(Ok(v)) => Some(v), }; if let Some(port) = port { - let (host, port, username) = match config.servers.iter() - .find(|e| e.name == host) - { + let (host, port, username) = match config.servers.iter().find(|e| e.name == host) { Some(server_config) => { let host = server_config.host.as_str(); let port = server_config.port.unwrap_or(port); - let username = server_config.username.as_ref().map(|e| e.as_str()).or(username); + let username = server_config + .username + .as_ref() + .map(|e| e.as_str()) + .or(username); if username.is_none() { println!("{} no username specified", "error:".red()); return; @@ -255,7 +257,8 @@ fn match_server_connect(matches: &clap::ArgMatches<'_>, config: &mumlib::config: port, username: username.to_string(), accept_invalid_cert: true, //TODO - }).map(|e| (e, host)); + }) + .map(|e| (e, host)); match response { Ok((e, host)) => { if let Some(CommandResponse::ServerConnect { welcome_message }) = e { @@ -272,10 +275,7 @@ fn match_server_connect(matches: &clap::ArgMatches<'_>, config: &mumlib::config: } } -fn match_server_config( - matches: &clap::ArgMatches<'_>, - config: &mut mumlib::config::Config, -) { +fn match_server_config(matches: &clap::ArgMatches<'_>, config: &mut mumlib::config::Config) { if let Some(server_name) = matches.value_of("server_name") { let server = config.servers.iter_mut().find(|s| s.name == server_name); if let Some(server) = server { @@ -373,10 +373,7 @@ fn match_server_config( } } -fn match_server_rename( - matches: &clap::ArgMatches<'_>, - config: &mut mumlib::config::Config, -) { +fn match_server_rename(matches: &clap::ArgMatches<'_>, config: &mut mumlib::config::Config) { //if let Some(servers) = &mut config.servers { let prev_name = matches.value_of("prev_name").unwrap(); let next_name = matches.value_of("next_name").unwrap(); @@ -388,10 +385,7 @@ fn match_server_rename( //} } -fn match_server_remove( - matches: &clap::ArgMatches<'_>, - config: &mut mumlib::config::Config, -) { +fn match_server_remove(matches: &clap::ArgMatches<'_>, config: &mut mumlib::config::Config) { let name = matches.value_of("name").unwrap(); //if let Some(servers) = &mut config.servers { match config.servers.iter().position(|server| server.name == name) { -- cgit v1.2.1 From 2fc37a27ef0d2705edc16165977e1d7849c4d850 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Mon, 2 Nov 2020 23:23:49 +0100 Subject: remove commented out code --- mumctl/src/main.rs | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'mumctl') diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs index 005e703..340539c 100644 --- a/mumctl/src/main.rs +++ b/mumctl/src/main.rs @@ -405,7 +405,6 @@ fn match_server_add(matches: &clap::ArgMatches<'_>, config: &mut mumlib::config: let port = matches.value_of("port").map(|s| s.parse().unwrap()); let username = matches.value_of("username").map(|s| s.to_string()); let password = matches.value_of("password").map(|s| s.to_string()); - //if let Some(servers) = &mut config.servers { if config.servers.iter().any(|s| s.name == name) { println!("{} a server named {} already exists", "error:".red(), name); } else { @@ -417,15 +416,6 @@ fn match_server_add(matches: &clap::ArgMatches<'_>, config: &mut mumlib::config: password, }); } - /*} else { - config.servers = vec![ServerConfig { - name, - host, - port, - username, - password, - }]; - }*/ } fn parse_status(server_state: &mumlib::state::Server) { -- 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 From 972c11fe66c17728981ec57796c78fb70c7bd180 Mon Sep 17 00:00:00 2001 From: Eskil Queseth Date: Mon, 2 Nov 2020 23:43:42 +0100 Subject: remove commented out code --- mumctl/src/main.rs | 3 --- 1 file changed, 3 deletions(-) (limited to 'mumctl') diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs index 340539c..cbad4c6 100644 --- a/mumctl/src/main.rs +++ b/mumctl/src/main.rs @@ -374,7 +374,6 @@ fn match_server_config(matches: &clap::ArgMatches<'_>, config: &mut mumlib::conf } fn match_server_rename(matches: &clap::ArgMatches<'_>, config: &mut mumlib::config::Config) { - //if let Some(servers) = &mut config.servers { let prev_name = matches.value_of("prev_name").unwrap(); let next_name = matches.value_of("next_name").unwrap(); if let Some(server) = config.servers.iter_mut().find(|s| s.name == prev_name) { @@ -382,12 +381,10 @@ fn match_server_rename(matches: &clap::ArgMatches<'_>, config: &mut mumlib::conf } else { println!("{} server {} not found", "error:".red(), prev_name); } - //} } fn match_server_remove(matches: &clap::ArgMatches<'_>, config: &mut mumlib::config::Config) { let name = matches.value_of("name").unwrap(); - //if let Some(servers) = &mut config.servers { match config.servers.iter().position(|server| server.name == name) { Some(idx) => { config.servers.remove(idx); -- cgit v1.2.1