make config file globbing optional

This commit is contained in:
Robin Appelman 2021-06-24 15:23:48 +02:00
commit 5cb1eb8e27
3 changed files with 12 additions and 5 deletions

View file

@ -7,7 +7,7 @@ use std::iter::once;
use std::path::PathBuf;
use thiserror::Error;
pub use nc::parse;
pub use nc::{parse, parse_glob};
use std::fmt::{Display, Formatter};
#[derive(Debug)]

View file

@ -82,8 +82,7 @@ fn merge_configs(input: Vec<(PathBuf, Value)>) -> Result<Value> {
Ok(Value::Array(merged))
}
pub fn parse(path: impl AsRef<Path>) -> Result<Config> {
let files = glob_config_files(path);
fn parse_files(files: Vec<PathBuf>) -> Result<Config> {
let parsed_files = files
.into_iter()
.map(|path| {
@ -114,6 +113,14 @@ pub fn parse(path: impl AsRef<Path>) -> Result<Config> {
})
}
pub fn parse(path: impl AsRef<Path>) -> Result<Config> {
parse_files(glob_config_files(path))
}
pub fn parse_glob(path: impl AsRef<Path>) -> Result<Config> {
parse_files(glob_config_files(path))
}
fn parse_db_options(parsed: &Value) -> Result<Database> {
match parsed["dbtype"].as_str() {
Some("mysql") => {
@ -546,7 +553,7 @@ fn test_parse_redis_cluster() {
#[test]
fn test_parse_config_multiple() {
let config = config_from_file("tests/configs/multiple/config.php");
let config = parse_glob("tests/configs/multiple/config.php").unwrap();
assert_eq!("https://cloud.example.com", config.nextcloud_url);
assert_eq!("oc_", config.database_prefix);
assert_debug_equal(