diff options
| author | Rubens Brandao <git@rubens.io> | 2021-03-28 20:58:16 +0200 |
|---|---|---|
| committer | Rubens Brandao <git@rubens.io> | 2021-03-28 20:58:16 +0200 |
| commit | 4b12f3e87ed12ed5b070f23d73f8288cd5b109fd (patch) | |
| tree | 1f0ebc6d0a0af9f657badcc6eebe1d158ac6f83d /mumctl | |
| parent | 8501432530f19cb2be86815697c82abbe4482275 (diff) | |
| download | mum-4b12f3e87ed12ed5b070f23d73f8288cd5b109fd.tar.gz | |
Finish the password implementation
Diffstat (limited to 'mumctl')
| -rw-r--r-- | mumctl/src/main.rs | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/mumctl/src/main.rs b/mumctl/src/main.rs index d07a482..65dac61 100644 --- a/mumctl/src/main.rs +++ b/mumctl/src/main.rs @@ -59,6 +59,7 @@ fn main() { .about("Connect to a server") .arg(Arg::with_name("host").required(true)) .arg(Arg::with_name("username")) + .arg(Arg::with_name("password")) .arg( Arg::with_name("port") .long("port") @@ -395,13 +396,14 @@ fn process_matches(matches: ArgMatches, config: &mut Config, app: &mut App) -> R fn match_server_connect(matches: &clap::ArgMatches<'_>, config: &mumlib::config::Config) -> Result<(), Error> { let host = matches.value_of("host").unwrap(); let username = matches.value_of("username"); + let password = matches.value_of("password"); let port = match matches.value_of("port").map(|e| e.parse()) { None => Some(mumlib::DEFAULT_PORT), Some(Err(_)) => None, 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, password) = 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); @@ -413,20 +415,25 @@ fn match_server_connect(matches: &clap::ArgMatches<'_>, config: &mumlib::config: error!("no username specified"); return Ok(()); //TODO? return as error } - (host, port, username.unwrap()) + let password = server_config + .password + .as_deref() + .or(password); + (host, port, username.unwrap(), password) } None => { if username.is_none() { error!("no username specified"); return Ok(()); //TODO? return as error } - (host, port, username.unwrap()) + (host, port, username.unwrap(), password) } }; let response = send_command(Command::ServerConnect { host: host.to_string(), port, username: username.to_string(), + password: password.map(|x| x.to_string()), accept_invalid_cert: true, //TODO })? .map(|e| (e, host)); |
