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 <rishflab@hotmail.com>
This commit is contained in:
bors[bot] 2021-03-05 05:56:41 +00:00 committed by GitHub
commit 52483a5a43
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 24 deletions

View File

@ -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;
@ -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(),
};
@ -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 {
@ -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 {

View File

@ -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,
@ -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)]
@ -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,
}