From f48f71fd72acad3cd82c775ff99091292eb45c79 Mon Sep 17 00:00:00 2001 From: yse <70684173+hydra-yse@users.noreply.github.com> Date: Mon, 21 Jul 2025 10:06:01 +0200 Subject: [PATCH] feat[cli]: add flag to avoid printing qr codes (#970) --- cli/src/commands.rs | 43 ++++++++++++++++++++++++++----------------- cli/src/main.rs | 12 +++++++++--- 2 files changed, 35 insertions(+), 20 deletions(-) diff --git a/cli/src/commands.rs b/cli/src/commands.rs index 8b2de55..6a9a945 100644 --- a/cli/src/commands.rs +++ b/cli/src/commands.rs @@ -17,6 +17,8 @@ use rustyline::{hint::HistoryHinter, Completer, Helper, Hinter, Validator}; use serde::Serialize; use serde_json::to_string_pretty; +use crate::Args; + #[derive(Parser, Debug, Clone, PartialEq)] pub(crate) enum Command { /// Send a payment directly or via a swap @@ -315,6 +317,7 @@ macro_rules! wait_confirmation { pub(crate) async fn handle_command( rl: &mut Editor, sdk: &Arc, + args: &Args, command: Command, ) -> Result { Ok(match command { @@ -381,22 +384,26 @@ pub(crate) async fn handle_command( let mut result = command_result!(&response); result.push('\n'); - match sdk.parse(&response.destination).await? { - InputType::Bolt11 { invoice } => result.push_str(&build_qr_text(&invoice.bolt11)), - InputType::Bolt12Offer { offer, .. } => { - result.push_str(&build_qr_text(&offer.offer)) + if !args.no_qrs { + match sdk.parse(&response.destination).await? { + InputType::Bolt11 { invoice } => { + result.push_str(&build_qr_text(&invoice.bolt11)) + } + InputType::Bolt12Offer { offer, .. } => { + result.push_str(&build_qr_text(&offer.offer)) + } + InputType::LiquidAddress { address } => { + result.push_str(&build_qr_text(&address.to_uri().map_err(|e| { + anyhow!("Could not build BIP21 from address data: {e:?}") + })?)) + } + InputType::BitcoinAddress { address } => { + result.push_str(&build_qr_text(&address.to_uri().map_err(|e| { + anyhow!("Could not build BIP21 from address data: {e:?}") + })?)) + } + _ => {} } - InputType::LiquidAddress { address } => { - result.push_str(&build_qr_text(&address.to_uri().map_err(|e| { - anyhow!("Could not build BIP21 from address data: {e:?}") - })?)) - } - InputType::BitcoinAddress { address } => { - result.push_str(&build_qr_text(&address.to_uri().map_err(|e| { - anyhow!("Could not build BIP21 from address data: {e:?}") - })?)) - } - _ => {} } result } @@ -547,8 +554,10 @@ pub(crate) async fn handle_command( .await?; let mut result = command_result!(url.clone()); - result.push('\n'); - result.push_str(&build_qr_text(&url)); + if !args.no_qrs { + result.push('\n'); + result.push_str(&build_qr_text(&url)); + } result } Command::GetInfo => { diff --git a/cli/src/main.rs b/cli/src/main.rs index aa20236..6c869c6 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -30,6 +30,9 @@ pub(crate) struct Args { #[clap(long)] pub(crate) passphrase: Option, + + #[clap(long, default_value = "false")] + pub(crate) no_qrs: bool, } fn parse_network_arg(s: &str) -> Result { @@ -61,7 +64,10 @@ impl EventListener for CliEventListener { async fn main() -> Result<()> { let args = Args::parse(); - let data_dir_str = args.data_dir.unwrap_or(DEFAULT_DATA_DIR.to_string()); + let data_dir_str = args + .data_dir + .clone() + .unwrap_or(DEFAULT_DATA_DIR.to_string()); let data_dir = PathBuf::from(&data_dir_str); fs::create_dir_all(&data_dir)?; @@ -83,7 +89,7 @@ async fn main() -> Result<()> { } let mnemonic = persistence.get_or_create_mnemonic(args.phrase_path.as_deref())?; - let passphrase = args.passphrase; + let passphrase = args.passphrase.clone(); let network = args.network.unwrap_or(LiquidNetwork::Testnet); let breez_api_key = std::env::var_os("BREEZ_API_KEY") .map(|var| var.into_string().expect("Expected valid API key string")); @@ -124,7 +130,7 @@ async fn main() -> Result<()> { println!("{}", cli_res.unwrap_err()); continue; } - let res = handle_command(rl, &sdk, cli_res.unwrap()).await; + let res = handle_command(rl, &sdk, &args, cli_res.unwrap()).await; show_results(res)?; } Err(ReadlineError::Interrupted) => {