From 6a852bea8feaa3c3d69f67faa7ad65b95876a8c3 Mon Sep 17 00:00:00 2001 From: Ayush Singh Date: Thu, 20 Aug 2026 20:21:30 +0530 Subject: [PATCH] feat: add delete subcommand to remove config file --- src/commands.rs | 2 ++ src/config.rs | 13 +++++++++++++ src/main.rs | 7 ++++++- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/commands.rs b/src/commands.rs index 975f33be..c3ea71d7 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -95,6 +95,8 @@ pub struct CliOpts { #[derive(Debug, Subcommand, Clone, PartialEq)] #[command(rename_all = "snake")] pub enum CliSubCommand { + /// Delete configuration file. + Delete, /// Wallet operations. /// /// bdk-cli wallet operations includes all the basic wallet level tasks. diff --git a/src/config.rs b/src/config.rs index 60580037..214180c1 100644 --- a/src/config.rs +++ b/src/config.rs @@ -96,6 +96,19 @@ impl WalletConfig { } /// Get config for a wallet + pub fn delete(datadir: &Path) -> Result<(), Error> { + let config_path = datadir.join("config.toml"); + if config_path.exists() { + std::fs::remove_file(&config_path).map_err(|e| { + Error::Generic(format!("Failed to delete config file {config_path:?}: {e}")) + })?; + log::info!("Deleted config file at {config_path:?}"); + } else { + log::warn!("Config file {config_path:?} does not exist"); + } + Ok(()) + } + pub fn get_wallet_opts(&self, wallet_name: &str) -> Result { self.wallets .get(wallet_name) diff --git a/src/main.rs b/src/main.rs index 06e3ea24..10b09b55 100644 --- a/src/main.rs +++ b/src/main.rs @@ -52,7 +52,7 @@ async fn main() { async fn run(cli_opts: CliOpts) -> Result<(), Error> { let datadir = cli_opts.datadir.clone(); - let home_dir = prepare_home_dir(datadir)?; + let home_dir = prepare_home_dir(datadir.clone())?; match cli_opts.subcommand.clone() { CliSubCommand::Wallet { @@ -199,6 +199,11 @@ async fn run(cli_opts: CliOpts) -> Result<(), Error> { cmd.execute(&mut ctx)?.write_out(std::io::stdout())?; } + CliSubCommand::Delete => { + if let Some(dir) = datadir.as_deref() { + crate::config::WalletConfig::delete(dir)?; + } + }, CliSubCommand::Completions { shell } => { clap_complete::generate( shell,