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

@ -1,7 +1,7 @@
[package] [package]
name = "nextcloud-config-parser" name = "nextcloud-config-parser"
description = "Rust parser for nextcloud config files" description = "Rust parser for nextcloud config files"
version = "0.2.0" version = "0.2.2"
authors = ["Robin Appelman <robin@icewind.nl>"] authors = ["Robin Appelman <robin@icewind.nl>"]
edition = "2018" edition = "2018"
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"

View file

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

View file

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