Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ pub struct CliOpts {
#[arg(env = "DATADIR", short = 'd', long = "datadir")]
pub datadir: Option<std::path::PathBuf>,
/// Output results in pretty format (instead of JSON).
#[arg(long = "pretty")]
#[arg(long = "pretty", global = true)]
pub pretty: bool,
/// Top level cli sub-commands.
#[command(subcommand)]
Expand Down
15 changes: 7 additions & 8 deletions src/handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1093,9 +1093,8 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
}
};

let mut wallet = new_persisted_wallet(network, &mut persister, &wallet_opts)?;
let blockchain_client =
new_blockchain_client(&wallet_opts, &wallet, database_path)?;
let mut wallet = new_persisted_wallet(network, &mut persister, wallet_opts)?;
let blockchain_client = new_blockchain_client(wallet_opts, &wallet, database_path)?;

let result = handle_online_wallet_subcommand(
&mut wallet,
Expand All @@ -1108,10 +1107,10 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
};
#[cfg(not(any(feature = "sqlite", feature = "redb")))]
let result = {
let wallet = new_wallet(network, &wallet_opts)?;
let wallet = new_wallet(network, wallet_opts)?;
let blockchain_client =
crate::utils::new_blockchain_client(&wallet_opts, &wallet, database_path)?;
let mut wallet = new_wallet(network, &wallet_opts)?;
crate::utils::new_blockchain_client(wallet_opts, &wallet, database_path)?;
let mut wallet = new_wallet(network, wallet_opts)?;
handle_online_wallet_subcommand(&mut wallet, blockchain_client, online_subcommand)
.await?
};
Expand Down Expand Up @@ -1162,10 +1161,10 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
};
#[cfg(not(any(feature = "sqlite", feature = "redb")))]
let result = {
let mut wallet = new_wallet(network, &wallet_opts)?;
let mut wallet = new_wallet(network, wallet_opts)?;
handle_offline_wallet_subcommand(
&mut wallet,
&wallet_opts,
wallet_opts,
&cli_opts,
offline_subcommand.clone(),
)?
Expand Down
46 changes: 46 additions & 0 deletions tests/cli_flags.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) 2020-2025 Bitcoin Dev Kit Developers
//
// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
// You may not use this file except in accordance with one or both of these
// licenses.

//! CLI Flags Tests
//!
//! Tests for global CLI flags and their behavior

use std::process::Command;

#[test]
fn test_without_pretty_flag() {
let output = Command::new("cargo")
.args("run -- key generate".split_whitespace())
.output()
.unwrap();

assert!(output.status.success());

let stdout = String::from_utf8_lossy(&output.stdout);
assert!(serde_json::from_str::<serde_json::Value>(&stdout).is_ok());
}

#[test]
fn test_pretty_flag_before_subcommand() {
let output = Command::new("cargo")
.args("run -- --pretty key generate".split_whitespace())
.output()
.unwrap();

assert!(output.status.success());
}

#[test]
fn test_pretty_flag_after_subcommand() {
let output = Command::new("cargo")
.args("run -- key generate --pretty".split_whitespace())
.output()
.unwrap();

assert!(output.status.success());
}
Loading