mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-08-06 13:34:38 -04:00
Add reset-config command that allows removing config file
This commit is contained in:
parent
967736766b
commit
fe33e02f46
3 changed files with 27 additions and 4 deletions
|
@ -47,6 +47,10 @@ pub enum Command {
|
||||||
},
|
},
|
||||||
History,
|
History,
|
||||||
Resume(Resume),
|
Resume(Resume),
|
||||||
|
ResetConfig {
|
||||||
|
#[structopt(flatten)]
|
||||||
|
config: Config,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(structopt::StructOpt, Debug)]
|
#[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 anyhow::{Context, Result};
|
||||||
use config::{Config, ConfigError};
|
use config::{Config, ConfigError};
|
||||||
use dialoguer::{theme::ColorfulTheme, Input};
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
@ -139,8 +154,10 @@ mod tests {
|
||||||
};
|
};
|
||||||
|
|
||||||
initial_setup(config_path.clone(), || Ok(expected.clone())).unwrap();
|
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);
|
assert_eq!(expected, actual);
|
||||||
|
|
||||||
|
reset_config(Some(config_path.clone())).unwrap();
|
||||||
|
assert!(!config_path.exists());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,8 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
cli::{Command, Options, Resume},
|
cli::{Command, Options, Resume},
|
||||||
config::{
|
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};
|
use anyhow::{Context, Result};
|
||||||
|
@ -204,6 +205,7 @@ async fn main() -> Result<()> {
|
||||||
tokio::spawn(async move { event_loop.run().await });
|
tokio::spawn(async move { event_loop.run().await });
|
||||||
bob::run(swap).await?;
|
bob::run(swap).await?;
|
||||||
}
|
}
|
||||||
|
Command::ResetConfig { config } => reset_config(config.config_path)?,
|
||||||
};
|
};
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue