libimagstore: Replace read with typed read
This commit is contained in:
parent
febecd85e5
commit
3ef5fcfab6
2 changed files with 7 additions and 12 deletions
|
@ -26,15 +26,12 @@ use error::StoreErrorKind as SEK;
|
||||||
/// Checks whether the store configuration has a key "implicit-create" which maps to a boolean
|
/// Checks whether the store configuration has a key "implicit-create" which maps to a boolean
|
||||||
/// value. If that key is present, the boolean is returned, otherwise false is returned.
|
/// value. If that key is present, the boolean is returned, otherwise false is returned.
|
||||||
pub fn config_implicit_store_create_allowed(config: &Option<Value>) -> Result<bool> {
|
pub fn config_implicit_store_create_allowed(config: &Option<Value>) -> Result<bool> {
|
||||||
use toml_query::read::TomlValueReadExt;
|
use toml_query::read::TomlValueReadTypeExt;
|
||||||
|
|
||||||
let key = "store.implicit-create";
|
let key = "store.implicit-create";
|
||||||
|
|
||||||
if let Some(ref t) = *config {
|
if let Some(ref t) = *config {
|
||||||
t.read(key)?
|
t.read_bool(key)?.ok_or(SE::from_kind(SEK::ConfigKeyMissingError(key)))
|
||||||
.ok_or(SE::from_kind(SEK::ConfigKeyMissingError(key)))?
|
|
||||||
.as_bool()
|
|
||||||
.ok_or(SE::from_kind(SEK::ConfigTypeError(key, "boolean")))
|
|
||||||
} else {
|
} else {
|
||||||
Ok(false)
|
Ok(false)
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,6 +36,7 @@ use glob::glob;
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
use walkdir::Iter as WalkDirIter;
|
use walkdir::Iter as WalkDirIter;
|
||||||
use toml_query::read::TomlValueReadExt;
|
use toml_query::read::TomlValueReadExt;
|
||||||
|
use toml_query::read::TomlValueReadTypeExt;
|
||||||
|
|
||||||
use error::{StoreError as SE, StoreErrorKind as SEK};
|
use error::{StoreError as SE, StoreErrorKind as SEK};
|
||||||
use error::ResultExt;
|
use error::ResultExt;
|
||||||
|
@ -1102,13 +1103,10 @@ fn has_main_section(t: &Value) -> Result<bool> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn has_imag_version_in_main_section(t: &Value) -> Result<bool> {
|
fn has_imag_version_in_main_section(t: &Value) -> Result<bool> {
|
||||||
use toml_query::read::TomlValueReadExt;
|
t.read_string("imag.version")?
|
||||||
|
.ok_or(SE::from_kind(SEK::ConfigKeyMissingError("imag.version")))
|
||||||
t.read("imag.version")?
|
.map(String::from)
|
||||||
.ok_or(SE::from_kind(SEK::ConfigKeyMissingError("imag.version")))?
|
.map(|s| ::semver::Version::parse(&s).is_ok())
|
||||||
.as_str()
|
|
||||||
.map(|s| ::semver::Version::parse(s).is_ok())
|
|
||||||
.ok_or(SE::from_kind(SEK::ConfigTypeError("imag.version", "String")))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue