feat[cli]: add flag to avoid printing qr codes (#970)

This commit is contained in:
yse
2025-07-21 10:06:01 +02:00
committed by GitHub
parent be8a9f42bb
commit f48f71fd72
2 changed files with 35 additions and 20 deletions

View File

@@ -17,6 +17,8 @@ use rustyline::{hint::HistoryHinter, Completer, Helper, Hinter, Validator};
use serde::Serialize; use serde::Serialize;
use serde_json::to_string_pretty; use serde_json::to_string_pretty;
use crate::Args;
#[derive(Parser, Debug, Clone, PartialEq)] #[derive(Parser, Debug, Clone, PartialEq)]
pub(crate) enum Command { pub(crate) enum Command {
/// Send a payment directly or via a swap /// Send a payment directly or via a swap
@@ -315,6 +317,7 @@ macro_rules! wait_confirmation {
pub(crate) async fn handle_command( pub(crate) async fn handle_command(
rl: &mut Editor<CliHelper, DefaultHistory>, rl: &mut Editor<CliHelper, DefaultHistory>,
sdk: &Arc<LiquidSdk>, sdk: &Arc<LiquidSdk>,
args: &Args,
command: Command, command: Command,
) -> Result<String> { ) -> Result<String> {
Ok(match command { Ok(match command {
@@ -381,22 +384,26 @@ pub(crate) async fn handle_command(
let mut result = command_result!(&response); let mut result = command_result!(&response);
result.push('\n'); result.push('\n');
match sdk.parse(&response.destination).await? { if !args.no_qrs {
InputType::Bolt11 { invoice } => result.push_str(&build_qr_text(&invoice.bolt11)), match sdk.parse(&response.destination).await? {
InputType::Bolt12Offer { offer, .. } => { InputType::Bolt11 { invoice } => {
result.push_str(&build_qr_text(&offer.offer)) 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 result
} }
@@ -547,8 +554,10 @@ pub(crate) async fn handle_command(
.await?; .await?;
let mut result = command_result!(url.clone()); let mut result = command_result!(url.clone());
result.push('\n'); if !args.no_qrs {
result.push_str(&build_qr_text(&url)); result.push('\n');
result.push_str(&build_qr_text(&url));
}
result result
} }
Command::GetInfo => { Command::GetInfo => {

View File

@@ -30,6 +30,9 @@ pub(crate) struct Args {
#[clap(long)] #[clap(long)]
pub(crate) passphrase: Option<String>, pub(crate) passphrase: Option<String>,
#[clap(long, default_value = "false")]
pub(crate) no_qrs: bool,
} }
fn parse_network_arg(s: &str) -> Result<LiquidNetwork, String> { fn parse_network_arg(s: &str) -> Result<LiquidNetwork, String> {
@@ -61,7 +64,10 @@ impl EventListener for CliEventListener {
async fn main() -> Result<()> { async fn main() -> Result<()> {
let args = Args::parse(); 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); let data_dir = PathBuf::from(&data_dir_str);
fs::create_dir_all(&data_dir)?; 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 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 network = args.network.unwrap_or(LiquidNetwork::Testnet);
let breez_api_key = std::env::var_os("BREEZ_API_KEY") let breez_api_key = std::env::var_os("BREEZ_API_KEY")
.map(|var| var.into_string().expect("Expected valid API key string")); .map(|var| var.into_string().expect("Expected valid API key string"));
@@ -124,7 +130,7 @@ async fn main() -> Result<()> {
println!("{}", cli_res.unwrap_err()); println!("{}", cli_res.unwrap_err());
continue; 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)?; show_results(res)?;
} }
Err(ReadlineError::Interrupted) => { Err(ReadlineError::Interrupted) => {