mirror of
https://forgejo.ellis.link/continuwuation/continuwuity.git
synced 2026-05-26 20:49:55 +00:00
fix: Add option to mark certain config sections as optional
Fixes #1290
This commit is contained in:
@@ -0,0 +1 @@
|
|||||||
|
Fix the generated configuration containing uncommented optional sections. Contributed by @Jade
|
||||||
@@ -1926,9 +1926,9 @@
|
|||||||
#
|
#
|
||||||
#admin_filter = ""
|
#admin_filter = ""
|
||||||
|
|
||||||
[global.antispam]
|
#[global.antispam]
|
||||||
|
|
||||||
[global.antispam.meowlnir]
|
#[global.antispam.meowlnir]
|
||||||
|
|
||||||
# The base URL on which to contact Meowlnir (before /_meowlnir/antispam).
|
# The base URL on which to contact Meowlnir (before /_meowlnir/antispam).
|
||||||
#
|
#
|
||||||
@@ -1953,7 +1953,7 @@
|
|||||||
#
|
#
|
||||||
#check_all_joins = false
|
#check_all_joins = false
|
||||||
|
|
||||||
[global.antispam.draupnir]
|
#[global.antispam.draupnir]
|
||||||
|
|
||||||
# The base URL on which to contact Draupnir (before /api/).
|
# The base URL on which to contact Draupnir (before /api/).
|
||||||
#
|
#
|
||||||
|
|||||||
@@ -2261,7 +2261,11 @@ struct ListeningAddr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
#[config_example_generator(filename = "conduwuit-example.toml", section = "global.antispam")]
|
#[config_example_generator(
|
||||||
|
filename = "conduwuit-example.toml",
|
||||||
|
section = "global.antispam",
|
||||||
|
optional = "true"
|
||||||
|
)]
|
||||||
pub struct Antispam {
|
pub struct Antispam {
|
||||||
/// display: nested
|
/// display: nested
|
||||||
pub meowlnir: Option<MeowlnirConfig>,
|
pub meowlnir: Option<MeowlnirConfig>,
|
||||||
@@ -2272,7 +2276,8 @@ pub struct Antispam {
|
|||||||
#[derive(Clone, Debug, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
#[config_example_generator(
|
#[config_example_generator(
|
||||||
filename = "conduwuit-example.toml",
|
filename = "conduwuit-example.toml",
|
||||||
section = "global.antispam.meowlnir"
|
section = "global.antispam.meowlnir",
|
||||||
|
optional = "true"
|
||||||
)]
|
)]
|
||||||
pub struct MeowlnirConfig {
|
pub struct MeowlnirConfig {
|
||||||
/// The base URL on which to contact Meowlnir (before /_meowlnir/antispam).
|
/// The base URL on which to contact Meowlnir (before /_meowlnir/antispam).
|
||||||
@@ -2301,7 +2306,8 @@ pub struct MeowlnirConfig {
|
|||||||
#[derive(Clone, Debug, Deserialize)]
|
#[derive(Clone, Debug, Deserialize)]
|
||||||
#[config_example_generator(
|
#[config_example_generator(
|
||||||
filename = "conduwuit-example.toml",
|
filename = "conduwuit-example.toml",
|
||||||
section = "global.antispam.draupnir"
|
section = "global.antispam.draupnir",
|
||||||
|
optional = "true"
|
||||||
)]
|
)]
|
||||||
pub struct DraupnirConfig {
|
pub struct DraupnirConfig {
|
||||||
/// The base URL on which to contact Draupnir (before /api/).
|
/// The base URL on which to contact Draupnir (before /api/).
|
||||||
|
|||||||
@@ -73,7 +73,13 @@ fn generate_example(input: &ItemStruct, args: &[Meta], write: bool) -> Result<To
|
|||||||
.expect("written to config file");
|
.expect("written to config file");
|
||||||
}
|
}
|
||||||
|
|
||||||
file.write_fmt(format_args!("\n[{section}]\n"))
|
let optional = settings.get("optional").is_some_and(|v| v == "true");
|
||||||
|
let section_header = if optional {
|
||||||
|
format!("\n#[{section}]\n")
|
||||||
|
} else {
|
||||||
|
format!("\n[{section}]\n")
|
||||||
|
};
|
||||||
|
file.write_fmt(format_args!("{section_header}"))
|
||||||
.expect("written to config file");
|
.expect("written to config file");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user