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`.
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 `--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

View File

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