mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-04-20 16:06:00 -04:00
Add reset-config command that allows removing config file
This commit is contained in:
parent
967736766b
commit
fe33e02f46
@ -47,6 +47,10 @@ pub enum Command {
|
||||
},
|
||||
History,
|
||||
Resume(Resume),
|
||||
ResetConfig {
|
||||
#[structopt(flatten)]
|
||||
config: Config,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(structopt::StructOpt, Debug)]
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::fs::ensure_directory_exists;
|
||||
use crate::fs::{default_config_path, ensure_directory_exists};
|
||||
use anyhow::{Context, Result};
|
||||
use config::{Config, ConfigError};
|
||||
use dialoguer::{theme::ColorfulTheme, Input};
|
||||
@ -117,6 +117,21 @@ pub fn query_user_for_initial_testnet_config() -> Result<File> {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn reset_config(config_path: Option<PathBuf>) -> anyhow::Result<()> {
|
||||
let config_path = if let Some(config_path) = config_path {
|
||||
config_path
|
||||
} else {
|
||||
default_config_path()?
|
||||
};
|
||||
|
||||
fs::remove_file(&config_path)
|
||||
.with_context(|| format!("failed to remove config file {}", config_path.display()))?;
|
||||
|
||||
info!("Config file at {} was removed successfully. Initial setup will be re-triggered upon starting a swap.", config_path.as_path().display());
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@ -139,8 +154,10 @@ mod tests {
|
||||
};
|
||||
|
||||
initial_setup(config_path.clone(), || Ok(expected.clone())).unwrap();
|
||||
let actual = read_config(config_path).unwrap().unwrap();
|
||||
|
||||
let actual = read_config(config_path.clone()).unwrap().unwrap();
|
||||
assert_eq!(expected, actual);
|
||||
|
||||
reset_config(Some(config_path.clone())).unwrap();
|
||||
assert!(!config_path.exists());
|
||||
}
|
||||
}
|
||||
|
@ -15,7 +15,8 @@
|
||||
use crate::{
|
||||
cli::{Command, Options, Resume},
|
||||
config::{
|
||||
initial_setup, query_user_for_initial_testnet_config, read_config, ConfigNotInitialized,
|
||||
initial_setup, query_user_for_initial_testnet_config, read_config, reset_config,
|
||||
ConfigNotInitialized,
|
||||
},
|
||||
};
|
||||
use anyhow::{Context, Result};
|
||||
@ -204,6 +205,7 @@ async fn main() -> Result<()> {
|
||||
tokio::spawn(async move { event_loop.run().await });
|
||||
bob::run(swap).await?;
|
||||
}
|
||||
Command::ResetConfig { config } => reset_config(config.config_path)?,
|
||||
};
|
||||
|
||||
Ok(())
|
||||
|
Loading…
x
Reference in New Issue
Block a user