From 133d36b559190a6810dceef6c17ebb826aa1fcd0 Mon Sep 17 00:00:00 2001 From: Jedrzej Stuczynski Date: Wed, 5 Feb 2020 11:23:54 +0000 Subject: [PATCH] override config function --- sfw-provider/src/commands/mod.rs | 69 ++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) diff --git a/sfw-provider/src/commands/mod.rs b/sfw-provider/src/commands/mod.rs index d21d4a92bc..95651ffe13 100644 --- a/sfw-provider/src/commands/mod.rs +++ b/sfw-provider/src/commands/mod.rs @@ -5,5 +5,74 @@ pub mod init; pub mod run; pub(crate) fn override_config(mut config: Config, matches: &ArgMatches) -> Config { + if let Some(mix_host) = matches.value_of("mix-host") { + config = config.with_mix_listening_host(mix_host); + } + + if let Some(mix_port) = matches.value_of("mix-port").map(|port| port.parse::()) { + if let Err(err) = mix_port { + // if port was overridden, it must be parsable + panic!("Invalid port value provided - {:?}", err); + } + config = config.with_mix_listening_port(mix_port.unwrap()); + } + + if let Some(clients_host) = matches.value_of("clients-host") { + config = config.with_clients_listening_host(clients_host); + } + + if let Some(clients_port) = matches + .value_of("clients-port") + .map(|port| port.parse::()) + { + if let Err(err) = clients_port { + // if port was overridden, it must be parsable + panic!("Invalid port value provided - {:?}", err); + } + config = config.with_clients_listening_port(clients_port.unwrap()); + } + + if let Some(mix_announce_host) = matches.value_of("mix-announce-host") { + config = config.with_mix_announce_host(mix_announce_host); + } + + if let Some(mix_announce_port) = matches + .value_of("mix-announce-port") + .map(|port| port.parse::()) + { + if let Err(err) = mix_announce_port { + // if port was overridden, it must be parsable + panic!("Invalid port value provided - {:?}", err); + } + config = config.with_mix_announce_port(mix_announce_port.unwrap()); + } + + if let Some(clients_announce_host) = matches.value_of("clients-announce-host") { + config = config.with_clients_announce_host(clients_announce_host); + } + + if let Some(clients_announce_port) = matches + .value_of("clients-announce-port") + .map(|port| port.parse::()) + { + if let Err(err) = clients_announce_port { + // if port was overridden, it must be parsable + panic!("Invalid port value provided - {:?}", err); + } + config = config.with_clients_announce_port(clients_announce_port.unwrap()); + } + + if let Some(directory) = matches.value_of("directory") { + config = config.with_custom_directory(directory); + } + + if let Some(inboxes_dir) = matches.value_of("inboxes") { + config = config.with_custom_clients_inboxes(inboxes_dir); + } + + if let Some(clients_ledger) = matches.value_of("clients-ledger") { + config = config.with_custom_clients_ledger(clients_ledger); + } + config }