Deduplicate configuration path code

This commit is contained in:
Dirkjan Ochtman 2019-08-26 20:09:36 +02:00
parent 954f120ce2
commit 34586172b5

View File

@ -30,10 +30,7 @@ crate fn config_path() -> Result<PathBuf, ShellError> {
}
crate fn write_config(config: &IndexMap<String, Tagged<Value>>) -> Result<(), ShellError> {
let location = app_root(AppDataType::UserConfig, &APP_INFO)
.map_err(|err| ShellError::string(&format!("Couldn't open config file:\n{}", err)))?;
let filename = location.join("config.toml");
let filename = config_path()?;
touch(&filename)?;
let contents = value_to_toml_value(&Value::Object(Dictionary::new(config.clone())));
@ -48,10 +45,7 @@ crate fn write_config(config: &IndexMap<String, Tagged<Value>>) -> Result<(), Sh
crate fn config(span: impl Into<Span>) -> Result<IndexMap<String, Tagged<Value>>, ShellError> {
let span = span.into();
let location = app_root(AppDataType::UserConfig, &APP_INFO)
.map_err(|err| ShellError::string(&format!("Couldn't open config file:\n{}", err)))?;
let filename = location.join("config.toml");
let filename = config_path()?;
touch(&filename)?;
trace!("config file = {}", filename.display());