feat: better error messages and default strategy
This commit is contained in:
parent
fea08a344e
commit
449ac3f6a0
2 changed files with 13 additions and 11 deletions
1
TODO.md
1
TODO.md
|
@ -6,3 +6,4 @@ Features which need to be created before v0.1.0 release.
|
||||||
- [ ] Finalize configuration file scheme
|
- [ ] Finalize configuration file scheme
|
||||||
- [x] Implement identifiers
|
- [x] Implement identifiers
|
||||||
- [ ] Handle case when files already exist
|
- [ ] Handle case when files already exist
|
||||||
|
- [ ] Implement hardlink functionality
|
||||||
|
|
|
@ -43,35 +43,36 @@ impl DotfileRaw {
|
||||||
// TODO: improve error handling for parsing from raw TOML
|
// TODO: improve error handling for parsing from raw TOML
|
||||||
|
|
||||||
/// Create a new `DotfileRaw` from a `toml::Table`, which is a `Vec<Value>`.
|
/// Create a new `DotfileRaw` from a `toml::Table`, which is a `Vec<Value>`.
|
||||||
/// Will panic if the table does not contain the fields specified.
|
/// Will panic if the table does not contain the fields specified, except for 'strategy',
|
||||||
|
/// which is `symlink` by default.
|
||||||
fn from_table(table: Table) -> DotfileRaw {
|
fn from_table(table: Table) -> DotfileRaw {
|
||||||
let location = table
|
let location = table
|
||||||
.get("location")
|
.get("location")
|
||||||
.ok_or("Missing 'location' field.")
|
.ok_or("Missing 'location' field.")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_str()
|
.as_str()
|
||||||
.unwrap()
|
.expect("Location field must be a string pointing to a valid path!")
|
||||||
.to_string();
|
.to_string();
|
||||||
let destination = table
|
let destination = table
|
||||||
.get("destination")
|
.get("destination")
|
||||||
.ok_or("Missing 'destination' field.")
|
.ok_or("Missing 'destination' field.")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_str()
|
.as_str()
|
||||||
.unwrap()
|
.expect("Destination field must be a string pointing to a valid path!")
|
||||||
.to_string();
|
.to_string();
|
||||||
let strategy = table
|
let strategy = match table.get("strategy") {
|
||||||
.get("strategy")
|
Some(val) => val
|
||||||
.ok_or("Missing 'strategy' field.")
|
|
||||||
.unwrap()
|
|
||||||
.as_str()
|
.as_str()
|
||||||
.unwrap()
|
.expect("Strategy field must be a string!")
|
||||||
.to_string();
|
.to_string(),
|
||||||
|
None => "symlink".to_string(),
|
||||||
|
};
|
||||||
let identifiers = table
|
let identifiers = table
|
||||||
.get("identifiers")
|
.get("identifiers")
|
||||||
.ok_or("Missing 'identifiers' field.")
|
.ok_or("Missing 'identifiers' field.")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.as_array()
|
.as_array()
|
||||||
.unwrap()
|
.expect("Identifiers field must be an array of strings!")
|
||||||
.iter()
|
.iter()
|
||||||
.map(|x| x.as_str().unwrap().to_string())
|
.map(|x| x.as_str().unwrap().to_string())
|
||||||
.collect();
|
.collect();
|
||||||
|
|
Loading…
Reference in a new issue