Skip to content

Commit

Permalink
Fix repl and wallet help docs
Browse files Browse the repository at this point in the history
Was showing proxy opts description instead of repl description.
This is a workaround for `structopt` issue #333, #391, #418;
see TeXitoi/structopt#333 (comment)
  • Loading branch information
notmandatory committed Jan 9, 2022
1 parent f346d27 commit 098e935
Showing 1 changed file with 100 additions and 83 deletions.
183 changes: 100 additions & 83 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,84 +363,89 @@ pub enum WalletSubCommand {
OfflineWalletSubCommand(OfflineWalletSubCommand),
}

/// Wallet options
///
/// The wallet options required for all [`CliSubCommand::Wallet`] or [`CliSubCommand::Repl`]
/// sub-commands. These options capture wallet descriptor and blockchain client information. The
/// blockchain client details are only used for [`OnlineWalletSubCommand`]s.
///
/// # Example
///
/// ```
/// # use bdk::bitcoin::Network;
/// # use structopt::StructOpt;
/// # use bdk_cli::WalletOpts;
/// # #[cfg(feature = "electrum")]
/// # use bdk_cli::ElectrumOpts;
/// # #[cfg(feature = "esplora")]
/// # use bdk_cli::EsploraOpts;
/// # #[cfg(feature = "compact_filters")]
/// # use bdk_cli::CompactFilterOpts;
/// # #[cfg(feature = "rpc")]
/// # use bdk_cli::RpcOpts;
/// # #[cfg(any(feature = "compact_filters", feature = "electrum", feature="esplora"))]
/// # use bdk_cli::ProxyOpts;
///
/// let cli_args = vec!["wallet",
/// "--descriptor", "wpkh(tpubEBr4i6yk5nf5DAaJpsi9N2pPYBeJ7fZ5Z9rmN4977iYLCGco1VyjB9tvvuvYtfZzjD5A8igzgw3HeWeeKFmanHYqksqZXYXGsw5zjnj7KM9/44'/1'/0'/0/*)"];
///
/// // to get WalletOpt from OS command line args use:
/// // let wallet_opt = WalletOpt::from_args();
///
/// let wallet_opts = WalletOpts::from_iter(&cli_args);
///
/// let expected_wallet_opts = WalletOpts {
/// wallet: "main".to_string(),
/// verbose: false,
/// descriptor: "wpkh(tpubEBr4i6yk5nf5DAaJpsi9N2pPYBeJ7fZ5Z9rmN4977iYLCGco1VyjB9tvvuvYtfZzjD5A8igzgw3HeWeeKFmanHYqksqZXYXGsw5zjnj7KM9/44'/1'/0'/0/*)".to_string(),
/// change_descriptor: None,
/// #[cfg(feature = "electrum")]
/// electrum_opts: ElectrumOpts {
/// timeout: None,
/// server: "ssl://electrum.blockstream.info:60002".to_string(),
/// stop_gap: 10
/// },
/// #[cfg(feature = "esplora-ureq")]
/// esplora_opts: EsploraOpts {
/// server: "https://blockstream.info/testnet/api/".to_string(),
/// read_timeout: 5,
/// write_timeout: 5,
/// stop_gap: 10
/// },
/// #[cfg(feature = "esplora-reqwest")]
/// esplora_opts: EsploraOpts {
/// server: "https://blockstream.info/testnet/api/".to_string(),
/// conc: 4,
/// stop_gap: 10
/// },
/// #[cfg(feature = "compact_filters")]
/// compactfilter_opts: CompactFilterOpts{
/// address: vec!["127.0.0.1:18444".to_string()],
/// conn_count: 4,
/// skip_blocks: 0,
/// },
/// #[cfg(feature = "rpc")]
/// rpc_opts: RpcOpts{
/// address: "127.0.0.1:18443".to_string(),
/// auth: ("user".to_string(), "password".to_string()),
/// skip_blocks: None,
/// },
/// #[cfg(any(feature="compact_filters", feature="electrum", feature="esplora"))]
/// proxy_opts: ProxyOpts{
/// proxy: None,
/// proxy_auth: None,
/// retries: 5,
/// },
/// };
///
/// assert_eq!(expected_wallet_opts, wallet_opts);
/// ```
#[cfg_attr(not(doc), allow(missing_docs))]
#[cfg_attr(
doc,
doc = r#"
Wallet options
The wallet options required for all [`CliSubCommand::Wallet`] or [`CliSubCommand::Repl`]
sub-commands. These options capture wallet descriptor and blockchain client information. The
blockchain client details are only used for [`OnlineWalletSubCommand`]s.
# Example
```
# use bdk::bitcoin::Network;
# use structopt::StructOpt;
# use bdk_cli::WalletOpts;
# #[cfg(feature = "electrum")]
# use bdk_cli::ElectrumOpts;
# #[cfg(feature = "esplora")]
# use bdk_cli::EsploraOpts;
# #[cfg(feature = "compact_filters")]
# use bdk_cli::CompactFilterOpts;
# #[cfg(feature = "rpc")]
# use bdk_cli::RpcOpts;
# #[cfg(any(feature = "compact_filters", feature = "electrum", feature="esplora"))]
# use bdk_cli::ProxyOpts;
let cli_args = vec!["wallet",
"--descriptor", "wpkh(tpubEBr4i6yk5nf5DAaJpsi9N2pPYBeJ7fZ5Z9rmN4977iYLCGco1VyjB9tvvuvYtfZzjD5A8igzgw3HeWeeKFmanHYqksqZXYXGsw5zjnj7KM9/44'/1'/0'/0/*)"];
// to get WalletOpt from OS command line args use:
// let wallet_opt = WalletOpt::from_args();
let wallet_opts = WalletOpts::from_iter(&cli_args);
let expected_wallet_opts = WalletOpts {
wallet: "main".to_string(),
verbose: false,
descriptor: "wpkh(tpubEBr4i6yk5nf5DAaJpsi9N2pPYBeJ7fZ5Z9rmN4977iYLCGco1VyjB9tvvuvYtfZzjD5A8igzgw3HeWeeKFmanHYqksqZXYXGsw5zjnj7KM9/44'/1'/0'/0/*)".to_string(),
change_descriptor: None,
#[cfg(feature = "electrum")]
electrum_opts: ElectrumOpts {
timeout: None,
server: "ssl://electrum.blockstream.info:60002".to_string(),
stop_gap: 10
},
#[cfg(feature = "esplora-ureq")]
esplora_opts: EsploraOpts {
server: "https://blockstream.info/testnet/api/".to_string(),
read_timeout: 5,
write_timeout: 5,
stop_gap: 10
},
#[cfg(feature = "esplora-reqwest")]
esplora_opts: EsploraOpts {
server: "https://blockstream.info/testnet/api/".to_string(),
conc: 4,
stop_gap: 10
},
#[cfg(feature = "compact_filters")]
compactfilter_opts: CompactFilterOpts{
address: vec!["127.0.0.1:18444".to_string()],
conn_count: 4,
skip_blocks: 0,
},
#[cfg(feature = "rpc")]
rpc_opts: RpcOpts{
address: "127.0.0.1:18443".to_string(),
auth: ("user".to_string(), "password".to_string()),
skip_blocks: None,
},
#[cfg(any(feature="compact_filters", feature="electrum", feature="esplora"))]
proxy_opts: ProxyOpts{
proxy: None,
proxy_auth: None,
retries: 5,
},
};
assert_eq!(expected_wallet_opts, wallet_opts);
```
"#
)]
#[derive(Debug, StructOpt, Clone, PartialEq)]
pub struct WalletOpts {
/// Selects the wallet to use
Expand Down Expand Up @@ -477,9 +482,15 @@ pub struct WalletOpts {
pub proxy_opts: ProxyOpts,
}

/// Proxy Server options
///
/// Only activated for `compact_filters` or `electrum`
#[cfg_attr(not(doc), allow(missing_docs))]
#[cfg_attr(
doc,
doc = r#"
Proxy Server options
Only activated for `compact_filters` or `electrum`
"#
)]
#[cfg(any(feature = "compact_filters", feature = "electrum", feature = "esplora"))]
#[derive(Debug, StructOpt, Clone, PartialEq)]
pub struct ProxyOpts {
Expand Down Expand Up @@ -585,9 +596,15 @@ pub struct ElectrumOpts {
pub stop_gap: usize,
}

/// Esplora options
///
/// Esplora blockchain client information used by [`OnlineWalletSubCommand`]s.
#[cfg_attr(not(doc), allow(missing_docs))]
#[cfg_attr(
doc,
doc = r#"
Esplora options
Esplora blockchain client information used by [`OnlineWalletSubCommand`]s.
"#
)]
#[cfg(feature = "esplora-ureq")]
#[derive(Debug, StructOpt, Clone, PartialEq)]
pub struct EsploraOpts {
Expand Down

0 comments on commit 098e935

Please sign in to comment.