From 943c31cc72465357e268db86acde186b7c188271 Mon Sep 17 00:00:00 2001 From: Nutomic Date: Wed, 22 May 2024 14:39:01 +0200 Subject: [PATCH] Allow passing command line params via environment (fixes #4603) (#4729) * Allow passing command line params via environment (fixes #4603) * add prefix --------- Co-authored-by: SleeplessOne1917 <28871516+SleeplessOne1917@users.noreply.github.com> --- Cargo.toml | 2 +- src/lib.rs | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 3af72cb55..f474ed14e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -165,7 +165,7 @@ urlencoding = "2.1.3" enum-map = "2.7" moka = { version = "0.12.7", features = ["future"] } i-love-jesus = { version = "0.1.0" } -clap = { version = "4.5.4", features = ["derive"] } +clap = { version = "4.5.4", features = ["derive", "env"] } pretty_assertions = "1.4.0" [dependencies] diff --git a/src/lib.rs b/src/lib.rs index 61e8abd13..85e2110a6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -70,23 +70,25 @@ use url::Url; about = "A link aggregator for the fediverse", long_about = "A link aggregator for the fediverse.\n\nThis is the Lemmy backend API server. This will connect to a PostgreSQL database, run any pending migrations and start accepting API requests." )] +// TODO: Instead of defining individual env vars, only specify prefix once supported by clap. +// https://github.com/clap-rs/clap/issues/3221 pub struct CmdArgs { /// Don't run scheduled tasks. /// /// If you are running multiple Lemmy server processes, you probably want to disable scheduled tasks on /// all but one of the processes, to avoid running the tasks more often than intended. - #[arg(long, default_value_t = false)] + #[arg(long, default_value_t = false, env = "LEMMY_DISABLE_SCHEDULED_TASKS")] disable_scheduled_tasks: bool, /// Disables the HTTP server. /// /// This can be used to run a Lemmy server process that only performs scheduled tasks or activity sending. - #[arg(long, default_value_t = false)] + #[arg(long, default_value_t = false, env = "LEMMY_DISABLE_HTTP_SERVER")] disable_http_server: bool, /// Disable sending outgoing ActivityPub messages. /// /// Only pass this for horizontally scaled setups. /// See https://join-lemmy.org/docs/administration/horizontal_scaling.html for details. - #[arg(long, default_value_t = false)] + #[arg(long, default_value_t = false, env = "LEMMY_DISABLE_ACTIVITY_SENDING")] disable_activity_sending: bool, /// The index of this outgoing federation process. /// @@ -96,12 +98,12 @@ pub struct CmdArgs { /// Make you have exactly one server with each `i` running, otherwise federation will randomly send duplicates or nothing. /// /// See https://join-lemmy.org/docs/administration/horizontal_scaling.html for more detail. - #[arg(long, default_value_t = 1)] + #[arg(long, default_value_t = 1, env = "LEMMY_FEDERATE_PROCESS_INDEX")] federate_process_index: i32, /// How many outgoing federation processes you are starting in total. /// /// If set, make sure to set --federate-process-index differently for each. - #[arg(long, default_value_t = 1)] + #[arg(long, default_value_t = 1, env = "LEMMY_FEDERATE_PROCESS_COUNT")] federate_process_count: i32, }