mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-08-21 16:53:08 +02:00
Merge pull request #273 from taskchampion/issue269
Create a new doc if necessary in `ta config set`
This commit is contained in:
commit
c8533c86f5
1 changed files with 18 additions and 4 deletions
|
@ -184,10 +184,24 @@ impl Settings {
|
|||
.ok_or_else(|| anyhow!("Could not determine config file name"))?
|
||||
};
|
||||
|
||||
let mut document = fs::read_to_string(filename.clone())
|
||||
.context("Could not read existing configuration file")?
|
||||
.parse::<Document>()
|
||||
.context("Could not parse existing configuration file")?;
|
||||
let exists = filename.exists();
|
||||
|
||||
// try to create the parent directory if the file does not exist
|
||||
if !exists {
|
||||
if let Some(dir) = filename.parent() {
|
||||
fs::create_dir_all(dir)?;
|
||||
}
|
||||
}
|
||||
|
||||
// start with the existing document, or a blank document
|
||||
let mut document = if exists {
|
||||
fs::read_to_string(filename.clone())
|
||||
.context("Could not read existing configuration file")?
|
||||
.parse::<Document>()
|
||||
.context("Could not parse existing configuration file")?
|
||||
} else {
|
||||
Document::new()
|
||||
};
|
||||
|
||||
// set the value as the correct type
|
||||
match key {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue