mirror of
https://codeberg.org/icewind/nextcloud-config-parser.git
synced 2026-06-03 08:34:13 +02:00
fix parsing with new default comment
This commit is contained in:
parent
20d09d186d
commit
1da941262e
4 changed files with 65 additions and 2 deletions
|
|
@ -1,8 +1,10 @@
|
|||
use std::env::args;
|
||||
|
||||
use miette::Result;
|
||||
use nextcloud_config_parser::parse;
|
||||
|
||||
fn main() -> Result<()> {
|
||||
let config = parse("tests/configs/basic.php")?;
|
||||
let config = parse(args().nth(1).expect("no config file provided"))?;
|
||||
dbg!(config);
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,7 +53,7 @@ fn parse_php(path: impl AsRef<Path>) -> Result<Value> {
|
|||
}
|
||||
}
|
||||
|
||||
let php = match content.find("$CONFIG") {
|
||||
let php = match content.rfind("$CONFIG") {
|
||||
Some(pos) => content[pos + "$CONFIG".len()..]
|
||||
.trim()
|
||||
.trim_start_matches('='),
|
||||
|
|
|
|||
|
|
@ -81,6 +81,36 @@ fn test_parse_config_basic() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_config_example_comment() {
|
||||
let config = config_from_file("tests/configs/comment_example.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,
|
||||
);
|
||||
|
||||
assert_eq!(
|
||||
config.database.url(),
|
||||
"mysql://nextcloud:secret@127.0.0.1/nextcloud?ssl-mode=disabled"
|
||||
);
|
||||
|
||||
assert_debug_equal(
|
||||
RedisConfig::Single(parse_redis("redis://127.0.0.1")),
|
||||
config.redis,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_parse_implicit_prefix() {
|
||||
let config = config_from_file("tests/configs/implicit_prefix.php");
|
||||
|
|
|
|||
31
tests/configs/comment_example.php
Normal file
31
tests/configs/comment_example.php
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* WARNING
|
||||
*
|
||||
* This file gets modified by automatic processes and all lines that are not
|
||||
* active code (ie. comments) are lost during that process.
|
||||
*
|
||||
* If you want to document things with comments or use constants add your settings
|
||||
* in a '<NAME>.config.php' file which will be included and rendered into this file.
|
||||
*
|
||||
* Example:
|
||||
* <?php
|
||||
* $CONFIG = [];
|
||||
*
|
||||
* See also: https://docs.nextcloud.com/server/latest/admin_manual/configuration_server/config_sample_php_parameters.html#multiple-merged-configuration-files
|
||||
*/
|
||||
|
||||
$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",
|
||||
],
|
||||
];
|
||||
Loading…
Add table
Add a link
Reference in a new issue