Skip to content

Commit

Permalink
Merge #291
Browse files Browse the repository at this point in the history
291: Improve CLI help comments and "type" hints r=rishflab a=rishflab

The type hints are generated from the field names. This has the
unfortunate consequence of the config field becoming file_path which
does not really make sense people working on the codebase.

Co-authored-by: rishflab <[email protected]>
  • Loading branch information
bors[bot] and rishflab authored Mar 5, 2021
2 parents 4b99d68 + f92a8ac commit 52483a5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 24 deletions.
16 changes: 8 additions & 8 deletions swap/src/bin/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use std::sync::Arc;
use std::time::Duration;
use structopt::StructOpt;
use swap::bitcoin::{Amount, TxLock};
use swap::cli::command::{Arguments, Command, ConnectParams, MoneroParams};
use swap::cli::command::{AliceConnectParams, Arguments, Command, MoneroParams};
use swap::cli::config::{read_config, Config};
use swap::database::Database;
use swap::execution_params::GetExecutionParams;
Expand Down Expand Up @@ -66,7 +66,7 @@ async fn main() -> Result<()> {
tracing::subscriber::set_global_default(subscriber)?;
}

let config = match args.config {
let config = match args.file_path {
Some(config_path) => read_config(config_path)??,
None => Config::testnet(),
};
Expand All @@ -85,9 +85,9 @@ async fn main() -> Result<()> {
match args.cmd {
Command::BuyXmr {
connect_params:
ConnectParams {
alice_peer_id,
alice_addr,
AliceConnectParams {
peer_id: alice_peer_id,
multiaddr: alice_addr,
},
monero_params:
MoneroParams {
Expand Down Expand Up @@ -169,9 +169,9 @@ async fn main() -> Result<()> {
Command::Resume {
swap_id,
connect_params:
ConnectParams {
alice_peer_id,
alice_addr,
AliceConnectParams {
peer_id: alice_peer_id,
multiaddr: alice_addr,
},
monero_params:
MoneroParams {
Expand Down
55 changes: 39 additions & 16 deletions swap/src/cli/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ pub const DEFAULT_ALICE_PEER_ID: &str = "12D3KooWCdMKjesXMJz1SiZ7HgotrxuqhQJbP5s
pub const DEFAULT_STAGENET_MONERO_DAEMON_HOST: &str = "monero-stagenet.exan.tech";

#[derive(structopt::StructOpt, Debug)]
#[structopt(name = "xmr-btc-swap", about = "Atomically swap BTC for XMR")]
pub struct Arguments {
#[structopt(
long = "config",
help = "Provide a custom path to the configuration file. The configuration file must be a toml file.",
parse(from_os_str)
)]
pub config: Option<PathBuf>,
pub file_path: Option<PathBuf>,

#[structopt(long, help = "Activate debug logging.")]
pub debug: bool,
Expand All @@ -28,35 +29,48 @@ pub struct Arguments {
}

#[derive(structopt::StructOpt, Debug)]
#[structopt(name = "xmr_btc-swap", about = "XMR BTC atomic swap")]
pub enum Command {
/// Start a XMR for BTC swap
BuyXmr {
#[structopt(flatten)]
connect_params: ConnectParams,
connect_params: AliceConnectParams,

#[structopt(flatten)]
monero_params: MoneroParams,
},
/// Show a list of past ongoing and completed swaps
History,
/// Resume a swap
Resume {
#[structopt(long = "swap-id")]
#[structopt(
long = "swap-id",
help = "The swap id can be retrieved using the history subcommand"
)]
swap_id: Uuid,

#[structopt(flatten)]
connect_params: ConnectParams,
connect_params: AliceConnectParams,

#[structopt(flatten)]
monero_params: MoneroParams,
},
/// Try to cancel an ongoing swap (expert users only)
Cancel {
#[structopt(long = "swap-id")]
#[structopt(
long = "swap-id",
help = "The swap id can be retrieved using the history subcommand"
)]
swap_id: Uuid,

#[structopt(short, long)]
force: bool,
},
/// Try to cancel a swap and refund my BTC (expert users only)
Refund {
#[structopt(long = "swap-id")]
#[structopt(
long = "swap-id",
help = "The swap id can be retrieved using the history subcommand"
)]
swap_id: Uuid,

#[structopt(short, long)]
Expand All @@ -65,25 +79,34 @@ pub enum Command {
}

#[derive(structopt::StructOpt, Debug)]
pub struct ConnectParams {
#[structopt(long = "connect-peer-id", default_value = DEFAULT_ALICE_PEER_ID)]
pub alice_peer_id: PeerId,
pub struct AliceConnectParams {
#[structopt(
long = "seller-peer-id",
default_value = DEFAULT_ALICE_PEER_ID,
help = "The peer id of a specific swap partner can be optionally provided"
)]
pub peer_id: PeerId,

#[structopt(
long = "connect-addr",
default_value = DEFAULT_ALICE_MULTIADDR
long = "seller-addr",
default_value = DEFAULT_ALICE_MULTIADDR,
help = "The multiaddr of a specific swap partner can be optionally provided"
)]
pub alice_addr: Multiaddr,
pub multiaddr: Multiaddr,
}

#[derive(structopt::StructOpt, Debug)]
pub struct MoneroParams {
#[structopt(long = "receive-address", parse(try_from_str = parse_monero_address))]
#[structopt(long = "receive-address",
help = "Provide the monero address where you would like to receive monero",
parse(try_from_str = parse_monero_address)
)]
pub receive_monero_address: monero::Address,

#[structopt(
long = "monero-daemon-host",
default_value = DEFAULT_STAGENET_MONERO_DAEMON_HOST
long = "monero-daemon-host",
help = "Specify to connect to a monero daemon of your choice",
default_value = DEFAULT_STAGENET_MONERO_DAEMON_HOST
)]
pub monero_daemon_host: String,
}
Expand Down

0 comments on commit 52483a5

Please sign in to comment.