Fixed --base-path on windows (#4193)

* Fixed --base-path on windows

* Add support for optional args with default text
This commit is contained in:
Arkadiy Paronyan
2017-01-18 18:45:30 +01:00
committed by arkpar
parent e01636fc34
commit 77b14b2736
3 changed files with 38 additions and 10 deletions

View File

@@ -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<String>, display dir::default_data_path(), or |c: &Config| otry!(c.parity).base_path.clone().map(Some),
flag_db_path: Option<String>, 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(),

View File

@@ -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,
)*
)
}
}