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 std::time::Duration;
use structopt::StructOpt; use structopt::StructOpt;
use swap::bitcoin::{Amount, TxLock}; 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::cli::config::{read_config, Config};
use swap::database::Database; use swap::database::Database;
use swap::execution_params::GetExecutionParams; use swap::execution_params::GetExecutionParams;
@ -66,7 +66,7 @@ async fn main() -> Result<()> {
tracing::subscriber::set_global_default(subscriber)?; tracing::subscriber::set_global_default(subscriber)?;
} }
let config = match args.config { let config = match args.file_path {
Some(config_path) => read_config(config_path)??, Some(config_path) => read_config(config_path)??,
None => Config::testnet(), None => Config::testnet(),
}; };
@ -85,9 +85,9 @@ async fn main() -> Result<()> {
match args.cmd { match args.cmd {
Command::BuyXmr { Command::BuyXmr {
connect_params: connect_params:
ConnectParams { AliceConnectParams {
alice_peer_id, peer_id: alice_peer_id,
alice_addr, multiaddr: alice_addr,
}, },
monero_params: monero_params:
MoneroParams { MoneroParams {
@ -169,9 +169,9 @@ async fn main() -> Result<()> {
Command::Resume { Command::Resume {
swap_id, swap_id,
connect_params: connect_params:
ConnectParams { AliceConnectParams {
alice_peer_id, peer_id: alice_peer_id,
alice_addr, multiaddr: alice_addr,
}, },
monero_params: monero_params:
MoneroParams { 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"; pub const DEFAULT_STAGENET_MONERO_DAEMON_HOST: &str = "monero-stagenet.exan.tech";
#[derive(structopt::StructOpt, Debug)] #[derive(structopt::StructOpt, Debug)]
#[structopt(name = "xmr-btc-swap", about = "Atomically swap BTC for XMR")]
pub struct Arguments { pub struct Arguments {
#[structopt( #[structopt(
long = "config", long = "config",
help = "Provide a custom path to the configuration file. The configuration file must be a toml file.", help = "Provide a custom path to the configuration file. The configuration file must be a toml file.",
parse(from_os_str) parse(from_os_str)
)] )]
pub config: Option<PathBuf>, pub file_path: Option<PathBuf>,
#[structopt(long, help = "Activate debug logging.")] #[structopt(long, help = "Activate debug logging.")]
pub debug: bool, pub debug: bool,
@ -28,35 +29,48 @@ pub struct Arguments {
} }
#[derive(structopt::StructOpt, Debug)] #[derive(structopt::StructOpt, Debug)]
#[structopt(name = "xmr_btc-swap", about = "XMR BTC atomic swap")]
pub enum Command { pub enum Command {
/// Start a XMR for BTC swap
BuyXmr { BuyXmr {
#[structopt(flatten)] #[structopt(flatten)]
connect_params: ConnectParams, connect_params: AliceConnectParams,
#[structopt(flatten)] #[structopt(flatten)]
monero_params: MoneroParams, monero_params: MoneroParams,
}, },
/// Show a list of past ongoing and completed swaps
History, History,
/// Resume a swap
Resume { Resume {
#[structopt(long = "swap-id")] #[structopt(
long = "swap-id",
help = "The swap id can be retrieved using the history subcommand"
)]
swap_id: Uuid, swap_id: Uuid,
#[structopt(flatten)] #[structopt(flatten)]
connect_params: ConnectParams, connect_params: AliceConnectParams,
#[structopt(flatten)] #[structopt(flatten)]
monero_params: MoneroParams, monero_params: MoneroParams,
}, },
/// Try to cancel an ongoing swap (expert users only)
Cancel { Cancel {
#[structopt(long = "swap-id")] #[structopt(
long = "swap-id",
help = "The swap id can be retrieved using the history subcommand"
)]
swap_id: Uuid, swap_id: Uuid,
#[structopt(short, long)] #[structopt(short, long)]
force: bool, force: bool,
}, },
/// Try to cancel a swap and refund my BTC (expert users only)
Refund { Refund {
#[structopt(long = "swap-id")] #[structopt(
long = "swap-id",
help = "The swap id can be retrieved using the history subcommand"
)]
swap_id: Uuid, swap_id: Uuid,
#[structopt(short, long)] #[structopt(short, long)]
@ -65,24 +79,33 @@ pub enum Command {
} }
#[derive(structopt::StructOpt, Debug)] #[derive(structopt::StructOpt, Debug)]
pub struct ConnectParams { pub struct AliceConnectParams {
#[structopt(long = "connect-peer-id", default_value = DEFAULT_ALICE_PEER_ID)] #[structopt(
pub alice_peer_id: PeerId, 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( #[structopt(
long = "connect-addr", long = "seller-addr",
default_value = DEFAULT_ALICE_MULTIADDR 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)] #[derive(structopt::StructOpt, Debug)]
pub struct MoneroParams { 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, pub receive_monero_address: monero::Address,
#[structopt( #[structopt(
long = "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 default_value = DEFAULT_STAGENET_MONERO_DAEMON_HOST
)] )]
pub monero_daemon_host: String, pub monero_daemon_host: String,