diff --git a/CHANGELOG.md b/CHANGELOG.md index e6e1aab5..99652a3f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/swap/src/cli/command.rs b/swap/src/cli/command.rs index 9e106a78..d9422ab1 100644 --- a/swap/src/cli/command.rs +++ b/swap/src/cli/command.rs @@ -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, @@ -407,23 +407,14 @@ mod data { use super::*; pub fn data_dir_from(arg_dir: Option, testnet: bool) -> Result { - 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) - } - - fn testnet_default() -> Result { - Ok(os_default()?.join("testnet")) - } + let sub_directory = if testnet { "testnet" } else { "mainnet" }; - fn mainnet_default() -> Result { - Ok(os_default()?.join("mainnet")) + Ok(base_dir.join(sub_directory)) } fn os_default() -> Result { @@ -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")) ) ); }