mirror of
https://codeberg.org/icewind/nextcloud-config-parser.git
synced 2026-06-03 16:44:09 +02:00
update literal parser
This commit is contained in:
parent
59cd402f2f
commit
b388c2ccf0
4 changed files with 43 additions and 14 deletions
|
|
@ -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.4.1"
|
version = "0.4.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"
|
||||||
|
|
@ -11,7 +11,7 @@ documentation = "https://docs.rs/nextcloud-config-parser"
|
||||||
[dependencies]
|
[dependencies]
|
||||||
redis = { version = "0.21", optional = true }
|
redis = { version = "0.21", optional = true }
|
||||||
thiserror = "1"
|
thiserror = "1"
|
||||||
php-literal-parser = { version = "0.2", default-features = false }
|
php-literal-parser = { version = "0.3", default-features = false }
|
||||||
sqlx = { version = "0.5", features = ["any", "mysql", "sqlite", "postgres"], optional = true }
|
sqlx = { version = "0.5", features = ["any", "mysql", "sqlite", "postgres"], optional = true }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
|
|
|
||||||
14
src/lib.rs
14
src/lib.rs
|
|
@ -8,7 +8,6 @@ use std::path::PathBuf;
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
pub use nc::{parse, parse_glob};
|
pub use nc::{parse, parse_glob};
|
||||||
use std::fmt::{Display, Formatter};
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Config {
|
pub struct Config {
|
||||||
|
|
@ -77,7 +76,7 @@ type Result<T, E = Error> = std::result::Result<T, E>;
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
#[error("Error while parsing php literal: {0:#}")]
|
#[error("{0:#}")]
|
||||||
Php(PhpParseError),
|
Php(PhpParseError),
|
||||||
#[error("Provided config file doesn't seem to be a nextcloud config file: {0:#}")]
|
#[error("Provided config file doesn't seem to be a nextcloud config file: {0:#}")]
|
||||||
NotAConfig(#[from] NotAConfigError),
|
NotAConfig(#[from] NotAConfigError),
|
||||||
|
|
@ -91,20 +90,13 @@ pub enum Error {
|
||||||
NoUrl,
|
NoUrl,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Error)]
|
||||||
|
#[error("Error while parsing '{path}':\n{err}")]
|
||||||
pub struct PhpParseError {
|
pub struct PhpParseError {
|
||||||
err: php_literal_parser::ParseError,
|
err: php_literal_parser::ParseError,
|
||||||
source: String,
|
|
||||||
path: PathBuf,
|
path: PathBuf,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Display for PhpParseError {
|
|
||||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
|
||||||
let err = self.err.clone().with_source(&self.source);
|
|
||||||
write!(f, "{}", err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Error)]
|
#[derive(Debug, Error)]
|
||||||
pub enum DbError {
|
pub enum DbError {
|
||||||
#[error("unsupported database type {0}")]
|
#[error("unsupported database type {0}")]
|
||||||
|
|
|
||||||
21
src/nc.rs
21
src/nc.rs
|
|
@ -69,7 +69,6 @@ fn parse_php(path: impl AsRef<Path>) -> Result<Value> {
|
||||||
Error::Php(PhpParseError {
|
Error::Php(PhpParseError {
|
||||||
err,
|
err,
|
||||||
path: path.as_ref().into(),
|
path: path.as_ref().into(),
|
||||||
source: php.into(),
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
@ -835,3 +834,23 @@ fn test_parse_config_sqlite_default_db() {
|
||||||
&config.database,
|
&config.database,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_parse_config_nested_array() {
|
||||||
|
let config = config_from_file("tests/configs/nested_array.php");
|
||||||
|
assert_eq!("https://cloud.example.com", config.nextcloud_url);
|
||||||
|
assert_eq!("oc_", config.database_prefix);
|
||||||
|
assert_debug_equal(
|
||||||
|
&Database::MySql {
|
||||||
|
database: "nextcloud".to_string(),
|
||||||
|
username: "nextcloud".to_string(),
|
||||||
|
password: "secret".to_string(),
|
||||||
|
connect: DbConnect::Tcp {
|
||||||
|
host: "127.0.0.1".to_string(),
|
||||||
|
port: 3306,
|
||||||
|
},
|
||||||
|
ssl_options: SslOptions::Disabled,
|
||||||
|
},
|
||||||
|
&config.database,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
|
||||||
18
tests/configs/nested_array.php
Normal file
18
tests/configs/nested_array.php
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
$CONFIG = [
|
||||||
|
'overwrite.cli.url' => 'https://cloud.example.com',
|
||||||
|
'dbtype' => 'mysql',
|
||||||
|
'dbname' => 'nextcloud',
|
||||||
|
'dbhost' => '127.0.0.1',
|
||||||
|
'dbport' => '',
|
||||||
|
'dbtableprefix' => 'oc_',
|
||||||
|
'dbuser' => 'nextcloud',
|
||||||
|
'dbpassword' => 'secret',
|
||||||
|
'redis' => [
|
||||||
|
'host' => 'localhost'
|
||||||
|
],
|
||||||
|
'apps_paths' => [
|
||||||
|
['path' => '/foo', 'url' => '/foo'],
|
||||||
|
]
|
||||||
|
];
|
||||||
Loading…
Add table
Add a link
Reference in a new issue