diff --git a/swap/src/cli.rs b/swap/src/cli.rs index 5bc2c9a4..1f72e89d 100644 --- a/swap/src/cli.rs +++ b/swap/src/cli.rs @@ -26,8 +26,8 @@ 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, + #[structopt(flatten)] + config: Config, }, BuyXmr { #[structopt(long = "connect-peer-id")] @@ -42,8 +42,8 @@ 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, + #[structopt(flatten)] + config: Config, }, History, Resume(Resume), @@ -58,8 +58,8 @@ 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, + #[structopt(flatten)] + config: Config, }, BuyXmr { #[structopt(long = "swap-id")] @@ -71,11 +71,21 @@ pub enum Resume { #[structopt(long = "counterpart-addr")] alice_addr: Multiaddr, - #[structopt(long = "config", parse(from_os_str))] - config_path: Option, + #[structopt(flatten)] + config: Config, }, } +#[derive(structopt::StructOpt, Debug)] +pub struct Config { + #[structopt( + long = "config", + help = "Provide a custom path to a configuration file. The configuration file must be a toml file.", + parse(from_os_str) + )] + pub config_path: Option, +} + fn parse_btc(str: &str) -> anyhow::Result { let amount = bitcoin::Amount::from_str_in(str, ::bitcoin::Denomination::Bitcoin)?; Ok(amount) diff --git a/swap/src/main.rs b/swap/src/main.rs index babebe6e..78d1d7af 100644 --- a/swap/src/main.rs +++ b/swap/src/main.rs @@ -69,9 +69,9 @@ async fn main() -> Result<()> { listen_addr, send_monero, receive_bitcoin, - config_path, + config, } => { - let settings = init_settings(config_path)?; + let settings = init_settings(config.config_path)?; let swap_amounts = SwapAmounts { xmr: send_monero, @@ -108,9 +108,9 @@ async fn main() -> Result<()> { alice_addr, send_bitcoin, receive_monero, - config_path, + config, } => { - let settings = init_settings(config_path)?; + let settings = init_settings(config.config_path)?; let swap_amounts = SwapAmounts { btc: send_bitcoin, @@ -158,9 +158,9 @@ async fn main() -> Result<()> { Command::Resume(Resume::SellXmr { swap_id, listen_addr, - config_path, + config, }) => { - let settings = init_settings(config_path)?; + let settings = init_settings(config.config_path)?; let (bitcoin_wallet, monero_wallet) = setup_wallets(settings.wallets).await?; @@ -183,9 +183,9 @@ async fn main() -> Result<()> { swap_id, alice_peer_id, alice_addr, - config_path, + config, }) => { - let settings = init_settings(config_path)?; + let settings = init_settings(config.config_path)?; let (bitcoin_wallet, monero_wallet) = setup_wallets(settings.wallets).await?;