]> Untitled Git - bdk-cli/commitdiff
feat: add command for completions
authorVadim Anufriev <mailbox@vaan.io>
Tue, 6 Jan 2026 18:10:00 +0000 (22:10 +0400)
committerVadim Anufriev <mailbox@vaan.io>
Sat, 7 Feb 2026 19:01:00 +0000 (23:01 +0400)
CHANGELOG.md
Cargo.lock
Cargo.toml
src/commands.rs
src/handlers.rs

index 55a95b77973f0dd61dbb495ca8e93e295d13d943..24a1580c6156c4536247beed2d5ca6f6b9d5437e 100644 (file)
@@ -6,11 +6,12 @@ page. See [DEVELOPMENT_CYCLE.md](DEVELOPMENT_CYCLE.md) for more details.
 ## [Unreleased]
 - Add wallet subcommand `config` to save wallet configs
 - Add `wallets` command to list all wallets saved configs
+- Added `completions` subcommand to generate shell completions
 
 ## [2.0.0]
 
 - Removed MSRV and bumped Rust Edition to 2024
-- Add `--pretty` flag for formatting outputs in human-readable form
+- Added `--pretty` flag for formatting outputs in human-readable form
 - Updated `bdk_wallet ` to  `2.1.0`,  `bdk_bitcoind_rpc` to `0.21.0`, `bdk_esplora` to `0.22.1`, `bdk_kyoto` to `0.13.1` 
 - Updated `tracing-subscriber` to 0.3.20
 - Added `tr` script type to `compile` command to support creating taproot descriptors
index 98036e68639b61c8ff72edd6859dbbef6b0f3208..f126cfc6d1d72c4e14ecf7d93fe6e63f449a6d58 100644 (file)
@@ -203,6 +203,7 @@ dependencies = [
  "bdk_redb",
  "bdk_wallet",
  "clap",
+ "clap_complete",
  "cli-table",
  "dirs",
  "env_logger",
@@ -721,6 +722,15 @@ dependencies = [
  "strsim",
 ]
 
+[[package]]
+name = "clap_complete"
+version = "4.5.64"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "4c0da80818b2d95eca9aa614a30783e42f62bf5fdfee24e68cfb960b071ba8d1"
+dependencies = [
+ "clap",
+]
+
 [[package]]
 name = "clap_derive"
 version = "4.5.49"
index b7d610a6ad4656e861c19e075fdfbccf9f38c6fb..cf6bd78fcc968836d2d9a1b9b125f4eec4a56351 100644 (file)
@@ -14,6 +14,7 @@ license = "MIT"
 [dependencies]
 bdk_wallet = { version = "2.1.0", features = ["rusqlite", "keys-bip39", "compiler", "std"] }
 clap = { version = "4.5", features = ["derive","env"] }
+clap_complete = "4.5"
 dirs = {  version = "6.0.0" }
 env_logger = "0.11.6"
 log = "0.4"
index 14ad9eaee13552fc37c28eb79e9a38651b0d5753..96f9b881d44d72d4511afa53a1b5f26455b0b9ef 100644 (file)
@@ -18,6 +18,7 @@ use bdk_wallet::bitcoin::{
     bip32::{DerivationPath, Xpriv},
 };
 use clap::{Args, Parser, Subcommand, ValueEnum, value_parser};
+use clap_complete::Shell;
 
 #[cfg(any(feature = "electrum", feature = "esplora", feature = "rpc"))]
 use crate::utils::parse_proxy_auth;
@@ -127,7 +128,39 @@ pub enum CliSubCommand {
     },
     /// List all saved wallet configurations.
     Wallets,
+    /// Generate tab-completion scripts for your shell.
+    ///
+    /// Outputs a shell-specific completion script to stdout.
+    /// To enable completions you need to redirect this output into the appropriate location for your shell.
+    ///
+    /// Bash:
+    ///   bdk-cli completions bash > ~/.local/share/bash-completion/completions/bdk-cli
+    ///
+    /// Zsh:
+    ///   bdk-cli completions zsh > ~/.zfunc/_bdk-cli
+    ///   # Make sure ~/.zfunc is in your fpath (add to .zshrc):
+    ///   #   fpath=(~/.zfunc $fpath)
+    ///   #   autoload -Uz compinit && compinit
+    ///
+    /// Fish:
+    ///   bdk-cli completions fish > ~/.config/fish/completions/bdk-cli.fish
+    ///
+    /// PowerShell:
+    ///   bdk-cli completions powershell >> $PROFILE
+    ///
+    /// Elvish:
+    ///   bdk-cli completions elvish >> ~/.elvish/rc.elv
+    ///
+    /// After installing the completion script, restart your shell or source
+    /// the configuration file for the changes to take effect.
+    #[command(verbatim_doc_comment)]
+    Completions {
+        /// Target shell syntax
+        #[arg(value_enum)]
+        shell: Shell,
+    },
 }
+
 /// Wallet operation subcommands.
 #[derive(Debug, Subcommand, Clone, PartialEq)]
 pub enum WalletSubCommand {
index 1f867b41928f821a450007d953d7c755da35267e..0462e90d78b52ce7bf74805b520acea54c5ec949 100644 (file)
@@ -44,6 +44,7 @@ use bdk_wallet::{
     descriptor::{Descriptor, Legacy, Miniscript},
     miniscript::{Tap, descriptor::TapTree, policy::Concrete},
 };
+use clap::CommandFactory;
 use cli_table::{Cell, CellStruct, Style, Table, format::Justify};
 use serde_json::json;
 #[cfg(feature = "cbf")]
@@ -1422,6 +1423,16 @@ pub(crate) async fn handle_command(cli_opts: CliOpts) -> Result<String, Error> {
             let descriptor = handle_descriptor_command(cli_opts.network, desc_type, key, pretty)?;
             Ok(descriptor)
         }
+        CliSubCommand::Completions { shell } => {
+            clap_complete::generate(
+                shell,
+                &mut CliOpts::command(),
+                "bdk-cli",
+                &mut std::io::stdout(),
+            );
+
+            Ok("".to_string())
+        }
     };
     result
 }