Skip to content

Commit 52483a5

Browse files
bors[bot]rishflab
andauthored
Merge #291
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]>
2 parents 4b99d68 + f92a8ac commit 52483a5

File tree

2 files changed

+47
-24
lines changed

2 files changed

+47
-24
lines changed

swap/src/bin/swap.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use std::sync::Arc;
2020
use std::time::Duration;
2121
use structopt::StructOpt;
2222
use swap::bitcoin::{Amount, TxLock};
23-
use swap::cli::command::{Arguments, Command, ConnectParams, MoneroParams};
23+
use swap::cli::command::{AliceConnectParams, Arguments, Command, MoneroParams};
2424
use swap::cli::config::{read_config, Config};
2525
use swap::database::Database;
2626
use swap::execution_params::GetExecutionParams;
@@ -66,7 +66,7 @@ async fn main() -> Result<()> {
6666
tracing::subscriber::set_global_default(subscriber)?;
6767
}
6868

69-
let config = match args.config {
69+
let config = match args.file_path {
7070
Some(config_path) => read_config(config_path)??,
7171
None => Config::testnet(),
7272
};
@@ -85,9 +85,9 @@ async fn main() -> Result<()> {
8585
match args.cmd {
8686
Command::BuyXmr {
8787
connect_params:
88-
ConnectParams {
89-
alice_peer_id,
90-
alice_addr,
88+
AliceConnectParams {
89+
peer_id: alice_peer_id,
90+
multiaddr: alice_addr,
9191
},
9292
monero_params:
9393
MoneroParams {
@@ -169,9 +169,9 @@ async fn main() -> Result<()> {
169169
Command::Resume {
170170
swap_id,
171171
connect_params:
172-
ConnectParams {
173-
alice_peer_id,
174-
alice_addr,
172+
AliceConnectParams {
173+
peer_id: alice_peer_id,
174+
multiaddr: alice_addr,
175175
},
176176
monero_params:
177177
MoneroParams {

swap/src/cli/command.rs

+39-16
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ pub const DEFAULT_ALICE_PEER_ID: &str = "12D3KooWCdMKjesXMJz1SiZ7HgotrxuqhQJbP5s
1212
pub const DEFAULT_STAGENET_MONERO_DAEMON_HOST: &str = "monero-stagenet.exan.tech";
1313

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

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

3031
#[derive(structopt::StructOpt, Debug)]
31-
#[structopt(name = "xmr_btc-swap", about = "XMR BTC atomic swap")]
3232
pub enum Command {
33+
/// Start a XMR for BTC swap
3334
BuyXmr {
3435
#[structopt(flatten)]
35-
connect_params: ConnectParams,
36+
connect_params: AliceConnectParams,
3637

3738
#[structopt(flatten)]
3839
monero_params: MoneroParams,
3940
},
41+
/// Show a list of past ongoing and completed swaps
4042
History,
43+
/// Resume a swap
4144
Resume {
42-
#[structopt(long = "swap-id")]
45+
#[structopt(
46+
long = "swap-id",
47+
help = "The swap id can be retrieved using the history subcommand"
48+
)]
4349
swap_id: Uuid,
4450

4551
#[structopt(flatten)]
46-
connect_params: ConnectParams,
52+
connect_params: AliceConnectParams,
4753

4854
#[structopt(flatten)]
4955
monero_params: MoneroParams,
5056
},
57+
/// Try to cancel an ongoing swap (expert users only)
5158
Cancel {
52-
#[structopt(long = "swap-id")]
59+
#[structopt(
60+
long = "swap-id",
61+
help = "The swap id can be retrieved using the history subcommand"
62+
)]
5363
swap_id: Uuid,
5464

5565
#[structopt(short, long)]
5666
force: bool,
5767
},
68+
/// Try to cancel a swap and refund my BTC (expert users only)
5869
Refund {
59-
#[structopt(long = "swap-id")]
70+
#[structopt(
71+
long = "swap-id",
72+
help = "The swap id can be retrieved using the history subcommand"
73+
)]
6074
swap_id: Uuid,
6175

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

6781
#[derive(structopt::StructOpt, Debug)]
68-
pub struct ConnectParams {
69-
#[structopt(long = "connect-peer-id", default_value = DEFAULT_ALICE_PEER_ID)]
70-
pub alice_peer_id: PeerId,
82+
pub struct AliceConnectParams {
83+
#[structopt(
84+
long = "seller-peer-id",
85+
default_value = DEFAULT_ALICE_PEER_ID,
86+
help = "The peer id of a specific swap partner can be optionally provided"
87+
)]
88+
pub peer_id: PeerId,
7189

7290
#[structopt(
73-
long = "connect-addr",
74-
default_value = DEFAULT_ALICE_MULTIADDR
91+
long = "seller-addr",
92+
default_value = DEFAULT_ALICE_MULTIADDR,
93+
help = "The multiaddr of a specific swap partner can be optionally provided"
7594
)]
76-
pub alice_addr: Multiaddr,
95+
pub multiaddr: Multiaddr,
7796
}
7897

7998
#[derive(structopt::StructOpt, Debug)]
8099
pub struct MoneroParams {
81-
#[structopt(long = "receive-address", parse(try_from_str = parse_monero_address))]
100+
#[structopt(long = "receive-address",
101+
help = "Provide the monero address where you would like to receive monero",
102+
parse(try_from_str = parse_monero_address)
103+
)]
82104
pub receive_monero_address: monero::Address,
83105

84106
#[structopt(
85-
long = "monero-daemon-host",
86-
default_value = DEFAULT_STAGENET_MONERO_DAEMON_HOST
107+
long = "monero-daemon-host",
108+
help = "Specify to connect to a monero daemon of your choice",
109+
default_value = DEFAULT_STAGENET_MONERO_DAEMON_HOST
87110
)]
88111
pub monero_daemon_host: String,
89112
}

0 commit comments

Comments
 (0)