commit 1fc64c9ff65b3b92b3452f3c85993b7aea81eac0
parent 217bf9ff31d40059765c37c16b126d23e8fd76b8
Author: triesap <tyson@radroots.org>
Date: Sun, 15 Feb 2026 17:59:23 +0000
runtime: add shared service cli and nostr config primitives
- add shared cli args for config and identity flags
- add shared nostr service config fragment for logs relays and nip89 fields
- export service primitives from runtime crate root
- add unit test coverage for service config default optional fields
Diffstat:
2 files changed, 69 insertions(+), 0 deletions(-)
diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs
@@ -4,6 +4,7 @@ pub mod cli;
pub mod config;
pub mod error;
pub mod json;
+pub mod service;
pub mod signals;
pub mod tracing;
@@ -23,5 +24,8 @@ pub use error::RuntimeCliError;
pub use error::{RuntimeConfigError, RuntimeError, RuntimeTracingError};
pub use json::{JsonFile, JsonWriteOptions, RuntimeJsonError};
+pub use service::RadrootsNostrServiceConfig;
+#[cfg(feature = "cli")]
+pub use service::RadrootsServiceCliArgs;
pub use signals::shutdown_signal;
pub use tracing::{init, init_with};
diff --git a/runtime/src/service.rs b/runtime/src/service.rs
@@ -0,0 +1,65 @@
+use serde::{Deserialize, Serialize};
+
+#[cfg(feature = "cli")]
+use clap::{ArgAction, Args, ValueHint};
+#[cfg(feature = "cli")]
+use std::path::PathBuf;
+
+#[cfg(feature = "cli")]
+#[derive(Args, Debug, Clone)]
+pub struct RadrootsServiceCliArgs {
+ #[arg(
+ long,
+ value_name = "PATH",
+ value_hint = ValueHint::FilePath,
+ default_value = "config.toml",
+ help = "Path to the daemon configuration file (defaults to config.toml)"
+ )]
+ pub config: PathBuf,
+
+ #[arg(
+ long,
+ value_name = "PATH",
+ value_hint = ValueHint::FilePath,
+ help = "Path to the daemon identity file (json, txt, or raw 32-byte key; defaults to identity.json)"
+ )]
+ pub identity: Option<PathBuf>,
+
+ #[arg(
+ long,
+ action = ArgAction::SetTrue,
+ help = "Allow generating a new identity file if missing; if not set and identity file is absent, the daemon will fail"
+ )]
+ pub allow_generate_identity: bool,
+}
+
+#[derive(Debug, Serialize, Deserialize, Clone)]
+pub struct RadrootsNostrServiceConfig {
+ pub logs_dir: String,
+ #[serde(default)]
+ pub relays: Vec<String>,
+ #[serde(default)]
+ pub nip89_identifier: Option<String>,
+ #[serde(default)]
+ pub nip89_extra_tags: Vec<Vec<String>>,
+}
+
+#[cfg(test)]
+mod tests {
+ use super::RadrootsNostrServiceConfig;
+
+ #[test]
+ fn service_config_defaults_optional_fields() {
+ let cfg: RadrootsNostrServiceConfig = toml::from_str(
+ r#"
+logs_dir = "logs"
+"#,
+ )
+ .expect("service config should parse");
+
+ assert_eq!(cfg.logs_dir, "logs");
+ assert!(cfg.relays.is_empty());
+ assert_eq!(cfg.nip89_identifier, None);
+ assert!(cfg.nip89_extra_tags.is_empty());
+ }
+}