Newer
Older
#[derive(Serialize, Deserialize, Debug)]
pub struct Config {
// user address
pub address: Option<AccountId>,
}
impl std::default::Default for Config {
fn default() -> Self {
Self {
duniter_endpoint: String::from(data::LOCAL_DUNITER_ENDPOINT),
indexer_endpoint: String::from(data::LOCAL_INDEXER_ENDPOINT),
/// load config file and manage error if could not
pub fn load_conf() -> Config {
match confy::load(APP_NAME, None) {
Ok(cfg) => cfg,
Err(e) => {
log::warn!("met error while loading config file");
log::error!("{}", e);
log::info!("removing the old conf file and creating a new one");
let cfg = Config::default();
confy::store(APP_NAME, None, &cfg).expect("unable to write default config");
cfg
}
}
#[derive(Clone, Default, Debug, clap::Parser)]
pub enum Subcommand {
#[default]
/// Save config as modified by command line arguments
Save,
pub fn handle_command(data: Data, command: Subcommand) -> anyhow::Result<()> {
// match subcommand
match command {
println!(
"{}",
confy::get_configuration_file_path(APP_NAME, None)?.display()
);
}
Subcommand::Show => {
Subcommand::Save => {
confy::store(APP_NAME, None, &data.cfg).expect("unable to write config");
}