Skip to content

Commit

Permalink
Generate config docs from code
Browse files Browse the repository at this point in the history
  • Loading branch information
Nutomic committed Sep 20, 2021
1 parent 1e7f3a4 commit 6d29cec
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 8 deletions.
46 changes: 46 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions crates/utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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" }
23 changes: 16 additions & 7 deletions crates/utils/src/settings/structs.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -17,8 +18,10 @@ pub struct Settings {
#[default(None)]
pub setup: Option<SetupConfig>,
#[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,
Expand All @@ -27,14 +30,15 @@ pub struct Settings {
#[default("changeme")]
pub jwt_secret: String,
#[default(None)]
#[doku(example = "http://localhost:8080")]
pub pictrs_url: Option<String>,
#[default(None)]
pub additional_slurs: Option<String>,
#[default(20)]
pub actor_name_max_length: usize,
}

#[derive(Debug, Deserialize, Clone, SmartDefault)]
#[derive(Debug, Deserialize, Clone, SmartDefault, Doku)]
#[serde(default)]
pub struct CaptchaConfig {
#[default(false)]
Expand All @@ -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")]
Expand All @@ -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<String>,
pub smtp_password: Option<String>,
#[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)]
Expand All @@ -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)]
Expand All @@ -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<String>,
Expand Down
8 changes: 7 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = 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();

Expand Down

0 comments on commit 6d29cec

Please sign in to comment.