Made builder methods on config more generic to accept any kind of strings
This commit is contained in:
@@ -7,11 +7,11 @@ use pemstore::pemstore::PemStore;
|
||||
pub fn execute(matches: &ArgMatches) {
|
||||
println!("Initialising client...");
|
||||
|
||||
let id = matches.value_of("id").unwrap().to_string(); // required for now
|
||||
let id = matches.value_of("id").unwrap(); // required for now
|
||||
let mut config = crate::config::Config::new(id);
|
||||
|
||||
if let Some(provider_id) = matches.value_of("provider") {
|
||||
config = config.with_provider_id(provider_id.to_string());
|
||||
config = config.with_provider_id(provider_id);
|
||||
}
|
||||
|
||||
let mix_identity_keys = MixIdentityKeyPair::new();
|
||||
|
||||
@@ -15,11 +15,11 @@ pub fn execute(matches: &ArgMatches) {
|
||||
.expect("Failed to load config file");
|
||||
|
||||
if let Some(directory) = matches.value_of("directory") {
|
||||
config_file = config_file.with_custom_directory(directory.to_string());
|
||||
config_file = config_file.with_custom_directory(directory);
|
||||
}
|
||||
|
||||
if let Some(provider_id) = matches.value_of("provider") {
|
||||
config_file = config_file.with_provider_id(provider_id.to_string());
|
||||
config_file = config_file.with_provider_id(provider_id);
|
||||
}
|
||||
|
||||
if let Some(socket_type) = matches.value_of("socket-type") {
|
||||
|
||||
@@ -64,11 +64,12 @@ impl NymConfig for Config {
|
||||
}
|
||||
|
||||
impl Config {
|
||||
pub fn new(id: String) -> Self {
|
||||
pub fn new<S: Into<String>>(id: S) -> Self {
|
||||
Config::default().with_id(id)
|
||||
}
|
||||
|
||||
pub fn with_id(mut self, id: String) -> Self {
|
||||
pub fn with_id<S: Into<String>>(mut self, id: S) -> Self {
|
||||
let id = id.into();
|
||||
if self.client.private_identity_key_file.as_os_str().is_empty() {
|
||||
self.client.private_identity_key_file =
|
||||
self::Client::default_private_identity_key_file(&id);
|
||||
@@ -81,18 +82,18 @@ impl Config {
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_provider_id(mut self, id: String) -> Self {
|
||||
self.client.provider_id = id;
|
||||
pub fn with_provider_id<S: Into<String>>(mut self, id: S) -> Self {
|
||||
self.client.provider_id = id.into();
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_provider_auth_token(mut self, token: String) -> Self {
|
||||
self.client.provider_authtoken = Some(token);
|
||||
pub fn with_provider_auth_token<S: Into<String>>(mut self, token: S) -> Self {
|
||||
self.client.provider_authtoken = Some(token.into());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_custom_directory(mut self, directory_server: String) -> Self {
|
||||
self.client.directory_server = directory_server;
|
||||
pub fn with_custom_directory<S: Into<String>>(mut self, directory_server: S) -> Self {
|
||||
self.client.directory_server = directory_server.into();
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user