mirror of
https://github.com/aljazceru/breez-sdk-liquid.git
synced 2025-12-17 05:54:27 +01:00
feat[cli]: add flag to avoid printing qr codes (#970)
This commit is contained in:
@@ -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,8 +384,11 @@ pub(crate) async fn handle_command(
|
|||||||
let mut result = command_result!(&response);
|
let mut result = command_result!(&response);
|
||||||
result.push('\n');
|
result.push('\n');
|
||||||
|
|
||||||
|
if !args.no_qrs {
|
||||||
match sdk.parse(&response.destination).await? {
|
match sdk.parse(&response.destination).await? {
|
||||||
InputType::Bolt11 { invoice } => result.push_str(&build_qr_text(&invoice.bolt11)),
|
InputType::Bolt11 { invoice } => {
|
||||||
|
result.push_str(&build_qr_text(&invoice.bolt11))
|
||||||
|
}
|
||||||
InputType::Bolt12Offer { offer, .. } => {
|
InputType::Bolt12Offer { offer, .. } => {
|
||||||
result.push_str(&build_qr_text(&offer.offer))
|
result.push_str(&build_qr_text(&offer.offer))
|
||||||
}
|
}
|
||||||
@@ -398,6 +404,7 @@ pub(crate) async fn handle_command(
|
|||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
Command::FetchLightningLimits => {
|
Command::FetchLightningLimits => {
|
||||||
@@ -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());
|
||||||
|
if !args.no_qrs {
|
||||||
result.push('\n');
|
result.push('\n');
|
||||||
result.push_str(&build_qr_text(&url));
|
result.push_str(&build_qr_text(&url));
|
||||||
|
}
|
||||||
result
|
result
|
||||||
}
|
}
|
||||||
Command::GetInfo => {
|
Command::GetInfo => {
|
||||||
|
|||||||
@@ -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) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user