Avoid overwriting existing config with --seed-config

This commit is contained in:
Lukas Bergdoll 2018-09-09 12:13:28 +02:00 committed by Danilo Bargen
commit e8aa36beb3
2 changed files with 9 additions and 2 deletions

View file

@ -208,10 +208,17 @@ pub fn make_default_syntax_config() -> Result<PathBuf, TealdeerError> {
}
}
let syntax_config_file_path = config_dir.join(SYNTAX_CONFIG_FILE_NAME);
if syntax_config_file_path.is_file() {
return Err(ConfigError(format!(
"A configuration file already exists at {}, no action was taken.",
syntax_config_file_path.to_str().unwrap()
)));
}
let serialized_syntax_config = toml::to_string(&RawConfig::new())
.map_err(|err| ConfigError(format!("Failed to serialize default syntax config: {}", err)))?;
let syntax_config_file_path = config_dir.join(SYNTAX_CONFIG_FILE_NAME);
let mut syntax_config_file = fs::File::create(&syntax_config_file_path)
.map_err(map_io_err_to_config_err)?;
let _wc = syntax_config_file.write(serialized_syntax_config.as_bytes())

View file

@ -299,7 +299,7 @@ fn main() {
process::exit(0);
},
Err(ConfigError(msg)) => {
eprintln!("Could not look up syntax_config_path: {}", msg);
eprintln!("Could not create seed config: {}", msg);
process::exit(1);
},
Err(_) => {