From 61bfe42d1d306b256f3b64d5db2517c68293dee9 Mon Sep 17 00:00:00 2001 From: Arkadiy Paronyan Date: Wed, 18 Jan 2017 18:45:30 +0100 Subject: [PATCH] Fixed --base-path on windows (#4193) * Fixed --base-path on windows * Add support for optional args with default text --- parity/cli/mod.rs | 11 +++++++---- parity/cli/usage.rs | 22 ++++++++++++++++++++++ parity/configuration.rs | 15 +++++++++------ 3 files changed, 38 insertions(+), 10 deletions(-) diff --git a/parity/cli/mod.rs b/parity/cli/mod.rs index 2c008623a..0802cb67f 100644 --- a/parity/cli/mod.rs +++ b/parity/cli/mod.rs @@ -91,8 +91,6 @@ usage! { flag_no_download: bool = false, or |c: &Config| otry!(c.parity).no_download.clone(), flag_no_consensus: bool = false, or |c: &Config| otry!(c.parity).no_consensus.clone(), flag_chain: String = "homestead", or |c: &Config| otry!(c.parity).chain.clone(), - flag_base_path: String = dir::default_data_path(), or |c: &Config| otry!(c.parity).base_path.clone(), - flag_db_path: String = dir::CHAINS_PATH, or |c: &Config| otry!(c.parity).db_path.clone(), flag_keys_path: String = "$BASE/keys", or |c: &Config| otry!(c.parity).keys_path.clone(), flag_identity: String = "", or |c: &Config| otry!(c.parity).identity.clone(), @@ -289,6 +287,11 @@ usage! { flag_no_color: bool = false, or |c: &Config| otry!(c.misc).color.map(|c| !c).clone(), } + { + // Values with optional default value. + flag_base_path: Option, display dir::default_data_path(), or |c: &Config| otry!(c.parity).base_path.clone().map(Some), + flag_db_path: Option, display dir::CHAINS_PATH, or |c: &Config| otry!(c.parity).db_path.clone().map(Some), + } } @@ -547,8 +550,8 @@ mod tests { flag_no_download: false, flag_no_consensus: false, flag_chain: "xyz".into(), - flag_base_path: "$HOME/.parity".into(), - flag_db_path: "$HOME/.parity/chains".into(), + flag_base_path: Some("$HOME/.parity".into()), + flag_db_path: Some("$HOME/.parity/chains".into()), flag_keys_path: "$HOME/.parity/keys".into(), flag_identity: "".into(), diff --git a/parity/cli/usage.rs b/parity/cli/usage.rs index 235087168..1f9de6f17 100644 --- a/parity/cli/usage.rs +++ b/parity/cli/usage.rs @@ -43,6 +43,11 @@ macro_rules! usage { $field:ident : $typ:ty = $default:expr, or $from_config:expr, )* } + { + $( + $field_s:ident : $typ_s:ty, display $default_s:expr, or $from_config_s:expr, + )* + } ) => { use toml; use std::{fs, io, process}; @@ -108,6 +113,10 @@ macro_rules! usage { $( pub $field: $typ, )* + + $( + pub $field_s: $typ_s, + )* } impl Default for Args { @@ -120,6 +129,10 @@ macro_rules! usage { $( $field: $default.into(), )* + + $( + $field_s: Default::default(), + )* } } } @@ -132,6 +145,9 @@ macro_rules! usage { $( $field: Option<$typ>, )* + $( + $field_s: Option<$typ_s>, + )* } impl Args { @@ -206,6 +222,9 @@ macro_rules! usage { $( args.$field = self.$field.or_else(|| $from_config(&config)).unwrap_or_else(|| $default.into()); )* + $( + args.$field_s = self.$field_s.or_else(|| $from_config_s(&config)).unwrap_or(None); + )* args } @@ -222,6 +241,9 @@ macro_rules! usage { // "named argument never used" error // $field = $default, )* + $( + $field_s = $default_s, + )* ) } } diff --git a/parity/configuration.rs b/parity/configuration.rs index 42816a823..9a0b8d831 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -35,7 +35,7 @@ use helpers::{to_duration, to_mode, to_block_id, to_u256, to_pending_set, to_pri geth_ipc_path, parity_ipc_path, to_bootnodes, to_addresses, to_address, to_gas_limit, to_queue_strategy}; use params::{ResealPolicy, AccountsConfig, GasPricerConfig, MinerExtras}; use ethcore_logger::Config as LogConfig; -use dir::{Directories, default_hypervisor_path, default_local_path}; +use dir::{self, Directories, default_hypervisor_path, default_local_path, default_data_path}; use dapps::Configuration as DappsConfiguration; use signer::{Configuration as SignerConfiguration}; use updater::{UpdatePolicy, UpdateFilter, ReleaseTrack}; @@ -734,13 +734,16 @@ impl Configuration { use util::path; let local_path = default_local_path(); - let data_path = replace_home("", self.args.flag_datadir.as_ref().unwrap_or(&self.args.flag_base_path)); - - let db_path = if self.args.flag_datadir.is_some() { - replace_home(&data_path, &self.args.flag_db_path) + let base_path = self.args.flag_base_path.as_ref().map_or_else(|| default_data_path(), |s| s.clone()); + let data_path = replace_home("", self.args.flag_datadir.as_ref().unwrap_or(&base_path)); + let base_db_path = if self.args.flag_base_path.is_some() && self.args.flag_db_path.is_none() { + // If base_path is set and db_path is not we default to base path subdir instead of LOCAL. + "$BASE/chains" } else { - replace_home_for_db(&data_path, &local_path, &self.args.flag_db_path) + self.args.flag_db_path.as_ref().map_or(dir::CHAINS_PATH, |s| &s) }; + + let db_path = replace_home_for_db(&data_path, &local_path, &base_db_path); let keys_path = replace_home(&data_path, &self.args.flag_keys_path); let dapps_path = replace_home(&data_path, &self.args.flag_dapps_path); let ui_path = replace_home(&data_path, &self.args.flag_ui_path);