Skip to main content

quorum_private/cli/
config.rs

1//! This module contains the functions for the `config` command in the CLI.
2
3use colored::Colorize;
4use quorum_core::utility::config::Config;
5
6/// Changes the value of a configuration setting in the config file.
7///
8/// # Arguments
9/// * `config_name` - The name of the configuration setting to change.
10/// * `config_value` - The new value for the configuration setting.
11///
12/// # Example
13/// ```rust
14/// change_config_value("server_host", "0.0.0.0");
15/// change_config_value("server_port", "8080");
16///```
17pub fn change_config_value(config_name: &str, config_value: &str) {
18    let result = Config::update(config_name, config_value);
19
20    if let Err(e) = result {
21        println!("Failed to update config value: {}", e);
22    } else {
23        println!("Config value updated successfully.");
24    }
25}
26
27/// Prints all the configuration settings in a formatted table.
28pub fn print_all() {
29    let cfg = Config::get();
30
31    println!();
32    println!(
33        "{}",
34        "┌────────────────────────────────────────────────────────────┐".dimmed()
35    );
36    println!("│ {} │", "SERVER CONFIGURATION".cyan().bold());
37    println!(
38        "{}",
39        "├────────────────────────────────────────────────────────────┤".dimmed()
40    );
41
42    println!(
43        "│ {:<22} : {:<33} │",
44        "server_host".yellow(),
45        cfg.server_host.white()
46    );
47    println!(
48        "│ {:<22} : {:<33} │",
49        "server_port".yellow(),
50        cfg.server_port.to_string().white()
51    );
52    println!(
53        "│ {:<22} : {:<33} │",
54        "server_url".yellow(),
55        cfg.server_url.white()
56    );
57
58    println!(
59        "{}",
60        "├────────────────────────────────────────────────────────────┤".dimmed()
61    );
62    println!(
63        "│ {:<22} : {:<33} │",
64        "surreal_data_path".yellow(),
65        cfg.surreal_data_path.white()
66    );
67    println!(
68        "│ {:<22} : {:<33} │",
69        "surreal_ns".yellow(),
70        cfg.surreal_ns.white()
71    );
72    println!(
73        "│ {:<22} : {:<33} │",
74        "surreal_db".yellow(),
75        cfg.surreal_db.white()
76    );
77
78    println!(
79        "{}",
80        "├────────────────────────────────────────────────────────────┤".dimmed()
81    );
82    let short_jwt = if cfg.jwt_secret.len() > 30 {
83        format!("{}...", &cfg.jwt_secret[..30])
84    } else {
85        cfg.jwt_secret.clone()
86    };
87    println!(
88        "│ {:<22} : {:<33} │",
89        "jwt_secret".yellow(),
90        short_jwt.dimmed()
91    );
92    println!(
93        "│ {:<22} : {:<33} │",
94        "jwt_access_minutes".yellow(),
95        format!("{} min", cfg.jwt_access_minutes).white()
96    );
97    println!(
98        "│ {:<22} : {:<33} │",
99        "jwt_refresh_days".yellow(),
100        format!("{} days", cfg.jwt_refresh_days).white()
101    );
102
103    println!(
104        "{}",
105        "├────────────────────────────────────────────────────────────┤".dimmed()
106    );
107    let testing_status = if cfg.enable_testing {
108        "true".green().bold()
109    } else {
110        "false".red()
111    };
112    println!(
113        "│ {:<22} : {:<42} │",
114        "enable_testing".yellow(),
115        testing_status
116    );
117    println!(
118        "│ {:<22} : {:<33} │",
119        "default_per_second".yellow(),
120        cfg.default_per_second.to_string().white()
121    );
122    println!(
123        "│ {:<22} : {:<33} │",
124        "default_burst_size".yellow(),
125        cfg.default_burst_size.to_string().white()
126    );
127    println!(
128        "│ {:<22} : {:<33} │",
129        "testing_per_second".yellow(),
130        cfg.testing_per_second.to_string().white()
131    );
132    println!(
133        "│ {:<22} : {:<33} │",
134        "testing_burst_size".yellow(),
135        cfg.testing_burst_size.to_string().white()
136    );
137
138    println!(
139        "{}",
140        "└────────────────────────────────────────────────────────────┘".dimmed()
141    );
142    println!();
143}