Skip to main content

hashiverse_server_lib/server/
args.rs

1//! # Server command-line arguments
2//!
3//! Clap-derived [`Args`] for the server binary: listen port, filesystem base path,
4//! disk quota (MB), passphrase source (direct env, mounted secret, or file path),
5//! log level, and a `skip_pq_commitment_bytes` testing flag.
6//!
7//! A builder-style constructor is provided for tests that want to spin up servers
8//! with synthetic configs without touching `clap`'s `std::env::args` parser.
9
10use clap::Parser;
11
12#[derive(Parser, Debug, Clone)]
13#[command(version, about, long_about = None)]
14pub struct Args {
15    /// Network port to use
16    #[arg(long, default_value_t = 443)]
17    pub port: u16,
18
19    /// Force local network
20    #[arg(long, default_value_t = false)]
21    pub force_local_network: bool,
22
23    /// Base path to server environments
24    #[arg(long, default_value = "./.hashiverse")]
25    pub base_path: String,
26
27    /// Maximum size of the posts database
28    #[arg(long, default_value_t = 20*1024)]
29    pub max_post_database_size_megabytes: usize,
30
31    /// From where can we read the passphrase passed into the container?
32    #[arg(long)]
33    pub passphrase_path: Option<String>,
34
35    /// Log level
36    #[arg(long, default_value = "trace")]
37    pub log_level: String,
38
39    /// Log level
40    #[arg(long, default_value = "false")]
41    pub skip_pq_commitment_bytes: bool
42}
43
44impl Args {
45    pub fn new() -> Self {
46        Args::parse()
47    }
48
49    pub fn default_for_testing() -> Self {
50        let selfie = Self::parse_from([""]);
51        selfie.with_skip_pq_commitment_bytes(true).with_force_local_network(true)
52    }
53
54
55    pub fn with_port(mut self, port: u16) -> Self {
56        self.port = port;
57        self
58    }
59
60    pub fn with_force_local_network(mut self, v: bool) -> Self {
61        self.force_local_network = v;
62        self
63    }
64
65    pub fn with_base_path(mut self, base_path: String) -> Self {
66        self.base_path = base_path;
67        self
68    }
69
70    pub fn with_max_post_database_size_megabytes(mut self, max_post_database_size_megabytes: usize) -> Self {
71        self.max_post_database_size_megabytes = max_post_database_size_megabytes;
72        self
73    }
74
75    pub fn with_skip_pq_commitment_bytes(mut self, skip_pq_commitment_bytes: bool) -> Self {
76        self.skip_pq_commitment_bytes = skip_pq_commitment_bytes;
77        self
78    }
79}
80
81impl Default for Args {
82    fn default() -> Self {
83        Self::parse_from([""])
84    }
85}