fix: Add option to mark certain config sections as optional

Fixes #1290
This commit is contained in:
Jade Ellis 2026-01-20 17:36:22 +00:00
parent 59346fc766
commit c85e710760
No known key found for this signature in database
GPG key ID: 8705A2A3EBF77BD2
4 changed files with 20 additions and 7 deletions

View file

@ -0,0 +1 @@
Fix the generated configuration containing uncommented optional sections. Contributed by @Jade

View file

@ -1926,9 +1926,9 @@
#
#admin_filter = ""
[global.antispam]
#[global.antispam]
[global.antispam.meowlnir]
#[global.antispam.meowlnir]
# The base URL on which to contact Meowlnir (before /_meowlnir/antispam).
#
@ -1953,7 +1953,7 @@
#
#check_all_joins = false
[global.antispam.draupnir]
#[global.antispam.draupnir]
# The base URL on which to contact Draupnir (before /api/).
#

View file

@ -2261,7 +2261,11 @@ struct ListeningAddr {
}
#[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 {
/// display: nested
pub meowlnir: Option<MeowlnirConfig>,
@ -2272,7 +2276,8 @@ pub struct Antispam {
#[derive(Clone, Debug, Deserialize)]
#[config_example_generator(
filename = "conduwuit-example.toml",
section = "global.antispam.meowlnir"
section = "global.antispam.meowlnir",
optional = "true"
)]
pub struct MeowlnirConfig {
/// The base URL on which to contact Meowlnir (before /_meowlnir/antispam).
@ -2301,7 +2306,8 @@ pub struct MeowlnirConfig {
#[derive(Clone, Debug, Deserialize)]
#[config_example_generator(
filename = "conduwuit-example.toml",
section = "global.antispam.draupnir"
section = "global.antispam.draupnir",
optional = "true"
)]
pub struct DraupnirConfig {
/// The base URL on which to contact Draupnir (before /api/).

View file

@ -73,7 +73,13 @@ fn generate_example(input: &ItemStruct, args: &[Meta], write: bool) -> Result<To
.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");
}