Change --data-dir for --data-base-dir

This commit is contained in:
Thomas Eizinger 2021-07-07 13:03:42 +10:00 committed by Daniel Karzel
parent 3b1789fe07
commit 40eccd089f
No known key found for this signature in database
GPG Key ID: 30C3FC2E438ADB6E
2 changed files with 19 additions and 24 deletions

View File

@ -34,6 +34,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- The commandline interface of the CLI to combine `--seller-addr` and `--seller-peer-id`. - The commandline interface of the CLI to combine `--seller-addr` and `--seller-peer-id`.
These two parameters have been merged into a parameter `--seller` that accepts a single [multiaddress](https://docs.libp2p.io/concepts/addressing/). These two parameters have been merged into a parameter `--seller` that accepts a single [multiaddress](https://docs.libp2p.io/concepts/addressing/).
The multiaddress must end with a `/p2p` protocol defining the seller's peer ID. The multiaddress must end with a `/p2p` protocol defining the seller's peer ID.
- The `--data-dir` option to `--data-base-dir`.
Previously, this option determined the final data directory, regardless of the `--testnet` flag.
With `--data-base-dir`, a subdirectory (either `testnet` or `mainnet`) will be created under the given path.
This allows using the same command with or without `--testnet`.
### Removed ### Removed

View File

@ -256,8 +256,8 @@ struct RawArguments {
testnet: bool, testnet: bool,
#[structopt( #[structopt(
long = "--data-dir", long = "--data-base-dir",
help = "Provide the data directory path to be used to store application data using testnet and mainnet as subfolder" help = "The base data directory to be used for mainnet / testnet specific data like database, wallets etc"
)] )]
data: Option<PathBuf>, data: Option<PathBuf>,
@ -407,23 +407,14 @@ mod data {
use super::*; use super::*;
pub fn data_dir_from(arg_dir: Option<PathBuf>, testnet: bool) -> Result<PathBuf> { pub fn data_dir_from(arg_dir: Option<PathBuf>, testnet: bool) -> Result<PathBuf> {
let dir = if let Some(dir) = arg_dir { let base_dir = match arg_dir {
dir Some(custom_base_dir) => custom_base_dir,
} else if testnet { None => os_default()?,
testnet_default()?
} else {
mainnet_default()?
}; };
Ok(dir) let sub_directory = if testnet { "testnet" } else { "mainnet" };
}
fn testnet_default() -> Result<PathBuf> { Ok(base_dir.join(sub_directory))
Ok(os_default()?.join("testnet"))
}
fn mainnet_default() -> Result<PathBuf> {
Ok(os_default()?.join("mainnet"))
} }
fn os_default() -> Result<PathBuf> { fn os_default() -> Result<PathBuf> {
@ -699,7 +690,7 @@ mod tests {
let raw_ars = vec![ let raw_ars = vec![
BINARY_NAME, BINARY_NAME,
"--data-dir", "--data-base-dir",
data_dir, data_dir,
"buy-xmr", "buy-xmr",
"--change-address", "--change-address",
@ -716,14 +707,14 @@ mod tests {
args, args,
ParseResult::Arguments( ParseResult::Arguments(
Arguments::buy_xmr_mainnet_defaults() Arguments::buy_xmr_mainnet_defaults()
.with_data_dir(PathBuf::from_str(data_dir).unwrap()) .with_data_dir(PathBuf::from_str(data_dir).unwrap().join("mainnet"))
) )
); );
let raw_ars = vec![ let raw_ars = vec![
BINARY_NAME, BINARY_NAME,
"--testnet", "--testnet",
"--data-dir", "--data-base-dir",
data_dir, data_dir,
"buy-xmr", "buy-xmr",
"--change-address", "--change-address",
@ -740,13 +731,13 @@ mod tests {
args, args,
ParseResult::Arguments( ParseResult::Arguments(
Arguments::buy_xmr_testnet_defaults() Arguments::buy_xmr_testnet_defaults()
.with_data_dir(PathBuf::from_str(data_dir).unwrap()) .with_data_dir(PathBuf::from_str(data_dir).unwrap().join("testnet"))
) )
); );
let raw_ars = vec![ let raw_ars = vec![
BINARY_NAME, BINARY_NAME,
"--data-dir", "--data-base-dir",
data_dir, data_dir,
"resume", "resume",
"--swap-id", "--swap-id",
@ -759,14 +750,14 @@ mod tests {
args, args,
ParseResult::Arguments( ParseResult::Arguments(
Arguments::resume_mainnet_defaults() Arguments::resume_mainnet_defaults()
.with_data_dir(PathBuf::from_str(data_dir).unwrap()) .with_data_dir(PathBuf::from_str(data_dir).unwrap().join("mainnet"))
) )
); );
let raw_ars = vec![ let raw_ars = vec![
BINARY_NAME, BINARY_NAME,
"--testnet", "--testnet",
"--data-dir", "--data-base-dir",
data_dir, data_dir,
"resume", "resume",
"--swap-id", "--swap-id",
@ -779,7 +770,7 @@ mod tests {
args, args,
ParseResult::Arguments( ParseResult::Arguments(
Arguments::resume_testnet_defaults() Arguments::resume_testnet_defaults()
.with_data_dir(PathBuf::from_str(data_dir).unwrap()) .with_data_dir(PathBuf::from_str(data_dir).unwrap().join("testnet"))
) )
); );
} }