diff --git a/Cargo.lock b/Cargo.lock index 8cd935abbe..be4cebcdb4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -977,6 +977,26 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fc4b29f4b9bb94bf267d57269fd0706d343a160937108e9619fe380645428abb" +[[package]] +name = "doku" +version = "0.9.0" +source = "git+https://github.com/anixe/doku?branch=issue/1#97e58175aa2972c003a8155d6f58aca91a9bfe88" +dependencies = [ + "doku-derive", +] + +[[package]] +name = "doku-derive" +version = "0.9.0" +source = "git+https://github.com/anixe/doku?branch=issue/1#97e58175aa2972c003a8155d6f58aca91a9bfe88" +dependencies = [ + "darling 0.13.0", + "proc-macro-error", + "proc-macro2 1.0.28", + "quote 1.0.9", + "syn 1.0.75", +] + [[package]] name = "either" version = "1.6.1" @@ -1869,6 +1889,7 @@ dependencies = [ "clokwerk", "diesel", "diesel_migrations", + "doku", "env_logger", "http-signature-normalization-actix", "lemmy_api", @@ -1904,6 +1925,7 @@ dependencies = [ "comrak", "deser-hjson", "diesel", + "doku", "futures", "http", "itertools", @@ -2509,6 +2531,30 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2 1.0.28", + "quote 1.0.9", + "syn 1.0.75", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2 1.0.28", + "quote 1.0.9", + "version_check", +] + [[package]] name = "proc-macro-hack" version = "0.5.19" diff --git a/Cargo.toml b/Cargo.toml index c73d63044a..ea3ea61b45 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -63,6 +63,7 @@ activitystreams = "0.7.0-alpha.11" actix-rt = { version = "2.2.0", default-features = false } serde_json = { version = "1.0.66", features = ["preserve_order"] } clokwerk = "0.3.5" +doku = { git = "https://github.com/anixe/doku", branch = "issue/1" } [dev-dependencies.cargo-husky] version = "1.5.0" diff --git a/crates/utils/Cargo.toml b/crates/utils/Cargo.toml index fda58cd163..365246960b 100644 --- a/crates/utils/Cargo.toml +++ b/crates/utils/Cargo.toml @@ -39,3 +39,4 @@ jsonwebtoken = "7.2.0" deser-hjson = "1.0.2" smart-default = "0.6.0" webpage = { version = "1.3.0", default-features = false, features = ["serde"] } +doku = { git = "https://github.com/anixe/doku", branch = "issue/1" } diff --git a/crates/utils/src/settings/structs.rs b/crates/utils/src/settings/structs.rs index 074cf87e81..2cab0d9637 100644 --- a/crates/utils/src/settings/structs.rs +++ b/crates/utils/src/settings/structs.rs @@ -1,7 +1,8 @@ +use doku::prelude::*; use serde::Deserialize; use std::net::{IpAddr, Ipv4Addr}; -#[derive(Debug, Deserialize, Clone, SmartDefault)] +#[derive(Debug, Deserialize, Clone, SmartDefault, Doku)] #[serde(default)] pub struct Settings { #[serde(default)] @@ -17,8 +18,10 @@ pub struct Settings { #[default(None)] pub setup: Option, #[default("unset")] + #[doku(example = "example.com")] pub hostname: String, #[default(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)))] + #[doku(as = "String")] pub bind: IpAddr, #[default(8536)] pub port: u16, @@ -27,6 +30,7 @@ pub struct Settings { #[default("changeme")] pub jwt_secret: String, #[default(None)] + #[doku(example = "http://localhost:8080")] pub pictrs_url: Option, #[default(None)] pub additional_slurs: Option, @@ -34,7 +38,7 @@ pub struct Settings { pub actor_name_max_length: usize, } -#[derive(Debug, Deserialize, Clone, SmartDefault)] +#[derive(Debug, Deserialize, Clone, SmartDefault, Doku)] #[serde(default)] pub struct CaptchaConfig { #[default(false)] @@ -43,7 +47,7 @@ pub struct CaptchaConfig { pub difficulty: String, } -#[derive(Debug, Deserialize, Clone, SmartDefault)] +#[derive(Debug, Deserialize, Clone, SmartDefault, Doku)] #[serde(default)] pub struct DatabaseConfig { #[default("lemmy")] @@ -60,16 +64,18 @@ pub struct DatabaseConfig { pub pool_size: u32, } -#[derive(Debug, Deserialize, Clone)] +#[derive(Debug, Deserialize, Clone, Doku)] pub struct EmailConfig { + #[doku(example = "localhost:25")] pub smtp_server: String, pub smtp_login: Option, pub smtp_password: Option, + #[doku(example = "noreply@example.com")] pub smtp_from_address: String, pub use_tls: bool, } -#[derive(Debug, Deserialize, Clone, SmartDefault)] +#[derive(Debug, Deserialize, Clone, SmartDefault, Doku)] #[serde(default)] pub struct FederationConfig { #[default(false)] @@ -82,7 +88,7 @@ pub struct FederationConfig { pub strict_allowlist: bool, } -#[derive(Debug, Deserialize, Clone, SmartDefault)] +#[derive(Debug, Deserialize, Clone, SmartDefault, Doku)] #[serde(default)] pub struct RateLimitConfig { #[default(180)] @@ -103,10 +109,13 @@ pub struct RateLimitConfig { pub image_per_second: i32, } -#[derive(Debug, Deserialize, Clone, SmartDefault)] +#[derive(Debug, Deserialize, Clone, SmartDefault, Doku)] pub struct SetupConfig { + #[doku(example = "admin")] pub admin_username: String, + #[doku(example = "my_passwd")] pub admin_password: String, + #[doku(example = "My Lemmy Instance")] pub site_name: String, #[default(None)] pub admin_email: Option, diff --git a/src/main.rs b/src/main.rs index 504ccc80ea..cc36ea4f9f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -21,13 +21,19 @@ use lemmy_utils::{ }; use lemmy_websocket::{chat_server::ChatServer, LemmyContext}; use reqwest::Client; -use std::{sync::Arc, thread}; +use std::{env, sync::Arc, thread}; use tokio::sync::Mutex; embed_migrations!(); #[actix_web::main] async fn main() -> Result<(), LemmyError> { + let args: Vec = env::args().collect(); + if args.len() == 2 && args[1] == "--print-config-docs" { + println!("{}", doku::to_json_val(&Settings::default())); + return Ok(()); + } + env_logger::init(); let settings = Settings::get();