Skip to main content

entdb_server/cli/
mod.rs

1/*
2 * Copyright 2026 EntDB Authors
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17use clap::Parser;
18
19#[derive(Debug, Clone, Parser)]
20#[command(name = "entdb", about = "EntDB PostgreSQL-compatible server")]
21pub struct Cli {
22    #[arg(
23        short = 'd',
24        long = "data-path",
25        alias = "data",
26        default_value = "ent.db"
27    )]
28    pub data_path: String,
29
30    #[arg(long, default_value = "127.0.0.1")]
31    pub host: String,
32
33    #[arg(short, long, default_value_t = 5433)]
34    pub port: u16,
35
36    #[arg(long, default_value_t = 1024)]
37    pub buffer_pool_size: usize,
38
39    #[arg(long, default_value_t = 256)]
40    pub max_connections: usize,
41
42    #[arg(long, default_value_t = 1_048_576)]
43    pub max_statement_bytes: usize,
44
45    #[arg(long, default_value_t = 30_000)]
46    pub query_timeout_ms: u64,
47
48    #[arg(long, default_value = "md5")]
49    pub auth_method: String,
50
51    #[arg(long, default_value_t = 4096)]
52    pub scram_iterations: usize,
53
54    #[arg(long, default_value = "entdb")]
55    pub auth_user: String,
56
57    #[arg(long, default_value = "entdb")]
58    pub auth_password: String,
59
60    #[arg(long)]
61    pub auth_password_env: Option<String>,
62
63    #[arg(long)]
64    pub auth_password_file: Option<String>,
65
66    #[arg(long, default_value = "full", value_parser = ["full", "normal", "off"])]
67    pub durability_mode: String,
68
69    #[arg(long)]
70    pub await_durable: bool,
71
72    #[arg(long)]
73    pub tls_cert: Option<String>,
74
75    #[arg(long)]
76    pub tls_key: Option<String>,
77}
78
79#[cfg(test)]
80mod tests {
81    use super::Cli;
82    use clap::Parser;
83
84    #[test]
85    fn cli_parses_data_path_long_flag() {
86        let cli = Cli::parse_from(["entdb", "--data-path", "./x.db"]);
87        assert_eq!(cli.data_path, "./x.db");
88    }
89
90    #[test]
91    fn cli_parses_data_alias_flag() {
92        let cli = Cli::parse_from(["entdb", "--data", "./y.db"]);
93        assert_eq!(cli.data_path, "./y.db");
94    }
95
96    #[test]
97    fn cli_parses_host_without_short_conflict() {
98        let cli = Cli::parse_from(["entdb", "--host", "0.0.0.0"]);
99        assert_eq!(cli.host, "0.0.0.0");
100    }
101
102    #[test]
103    fn cli_parses_durability_mode_flags() {
104        let cli = Cli::parse_from(["entdb", "--durability-mode", "normal", "--await-durable"]);
105        assert_eq!(cli.durability_mode, "normal");
106        assert!(cli.await_durable);
107
108        let off = Cli::parse_from(["entdb", "--durability-mode", "off"]);
109        assert_eq!(off.durability_mode, "off");
110        assert!(!off.await_durable);
111    }
112}