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_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<CliHelper, DefaultHistory>,
sdk: &Arc<LiquidSdk>,
args: &Args,
command: Command,
) -> Result<String> {
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 => {

View File

@@ -30,6 +30,9 @@ pub(crate) struct Args {
#[clap(long)]
pub(crate) passphrase: Option<String>,
#[clap(long, default_value = "false")]
pub(crate) no_qrs: bool,
}
fn parse_network_arg(s: &str) -> Result<LiquidNetwork, String> {
@@ -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) => {