Skip to content
Closed
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: 2 additions & 0 deletions src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
13 changes: 13 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<WalletOpts, Error> {
self.wallets
.get(wallet_name)
Expand Down
7 changes: 6 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down