diff --git a/swap/src/cli.rs b/swap/src/cli.rs index 5b0c30e2..5bc2c9a4 100644 --- a/swap/src/cli.rs +++ b/swap/src/cli.rs @@ -1,5 +1,6 @@ use crate::{bitcoin, monero}; use libp2p::{core::Multiaddr, PeerId}; +use std::path::PathBuf; use uuid::Uuid; #[derive(structopt::StructOpt, Debug)] @@ -24,6 +25,9 @@ pub enum Command { #[structopt(long = "receive-btc", help = "Bitcoin amount as floating point nr without denomination (e.g. 1.25)", parse(try_from_str = parse_btc))] receive_bitcoin: bitcoin::Amount, + + #[structopt(long = "config", parse(from_os_str))] + config_path: Option, }, BuyXmr { #[structopt(long = "connect-peer-id")] @@ -37,6 +41,9 @@ pub enum Command { #[structopt(long = "receive-xmr", help = "Monero amount as floating point nr without denomination (e.g. 125.1)", parse(try_from_str = parse_xmr))] receive_monero: monero::Amount, + + #[structopt(long = "config", parse(from_os_str))] + config_path: Option, }, History, Resume(Resume), @@ -50,6 +57,9 @@ pub enum Resume { #[structopt(long = "listen-address", default_value = "/ip4/127.0.0.1/tcp/9876")] listen_addr: Multiaddr, + + #[structopt(long = "config", parse(from_os_str))] + config_path: Option, }, BuyXmr { #[structopt(long = "swap-id")] @@ -60,6 +70,9 @@ pub enum Resume { #[structopt(long = "counterpart-addr")] alice_addr: Multiaddr, + + #[structopt(long = "config", parse(from_os_str))] + config_path: Option, }, } diff --git a/swap/src/main.rs b/swap/src/main.rs index 357f84ae..babebe6e 100644 --- a/swap/src/main.rs +++ b/swap/src/main.rs @@ -24,7 +24,7 @@ use fs::default_config_path; use prettytable::{row, Table}; use protocol::{alice, bob, bob::Builder, SwapAmounts}; use settings::Settings; -use std::sync::Arc; +use std::{path::PathBuf, sync::Arc}; use structopt::StructOpt; use trace::init_tracing; use tracing::{info, log::LevelFilter}; @@ -69,8 +69,9 @@ async fn main() -> Result<()> { listen_addr, send_monero, receive_bitcoin, + config_path, } => { - let settings = init_settings()?; + let settings = init_settings(config_path)?; let swap_amounts = SwapAmounts { xmr: send_monero, @@ -107,8 +108,9 @@ async fn main() -> Result<()> { alice_addr, send_bitcoin, receive_monero, + config_path, } => { - let settings = init_settings()?; + let settings = init_settings(config_path)?; let swap_amounts = SwapAmounts { btc: send_bitcoin, @@ -156,8 +158,9 @@ async fn main() -> Result<()> { Command::Resume(Resume::SellXmr { swap_id, listen_addr, + config_path, }) => { - let settings = init_settings()?; + let settings = init_settings(config_path)?; let (bitcoin_wallet, monero_wallet) = setup_wallets(settings.wallets).await?; @@ -180,8 +183,9 @@ async fn main() -> Result<()> { swap_id, alice_peer_id, alice_addr, + config_path, }) => { - let settings = init_settings()?; + let settings = init_settings(config_path)?; let (bitcoin_wallet, monero_wallet) = setup_wallets(settings.wallets).await?; @@ -205,8 +209,13 @@ async fn main() -> Result<()> { Ok(()) } -fn init_settings() -> Result { - let config_path = default_config_path()?; +fn init_settings(config_path: Option) -> Result { + let config_path = if let Some(config_path) = config_path { + config_path + } else { + default_config_path()? + }; + let config = match read_config(config_path.clone())? { Ok(config) => config, Err(ConfigNotInitialized {}) => {