Add cli flag for printing parsed config

This commit is contained in:
Joakim Frostegård 2022-07-05 11:15:53 +02:00
parent b07b08eb54
commit a852b290ca
2 changed files with 10 additions and 4 deletions

View file

@ -43,9 +43,6 @@
## Low priority ## Low priority
* config
* add flag to print parsed config when starting
* aquatic_udp * aquatic_udp
* what poll event capacity is actually needed? * what poll event capacity is actually needed?
* stagger connection cleaning intervals? * stagger connection cleaning intervals?

View file

@ -26,7 +26,7 @@ impl Default for LogLevel {
} }
} }
pub trait Config: Default + TomlConfig + DeserializeOwned { pub trait Config: Default + TomlConfig + DeserializeOwned + std::fmt::Debug {
fn get_log_level(&self) -> Option<LogLevel> { fn get_log_level(&self) -> Option<LogLevel> {
None None
} }
@ -36,6 +36,7 @@ pub trait Config: Default + TomlConfig + DeserializeOwned {
pub struct Options { pub struct Options {
config_file: Option<String>, config_file: Option<String>,
print_config: bool, print_config: bool,
print_parsed_config: bool,
print_version: bool, print_version: bool,
} }
@ -59,6 +60,9 @@ impl Options {
"-p" | "--print-config" => { "-p" | "--print-config" => {
options.print_config = true; options.print_config = true;
} }
"-P" => {
options.print_parsed_config = true;
}
"-v" | "--version" => { "-v" | "--version" => {
options.print_version = true; options.print_version = true;
} }
@ -148,6 +152,10 @@ where
start_logger(log_level)?; start_logger(log_level)?;
} }
if options.print_parsed_config {
println!("Running with configuration: {:#?}", config);
}
app_fn(config) app_fn(config)
} }
} }
@ -162,6 +170,7 @@ where
println!(" -c, --config-file Load config from this path"); println!(" -c, --config-file Load config from this path");
println!(" -h, --help Print this help message"); println!(" -h, --help Print this help message");
println!(" -p, --print-config Print default config"); println!(" -p, --print-config Print default config");
println!(" -P Print parsed config");
println!(" -v, --version Print version information"); println!(" -v, --version Print version information");
if let Some(error) = opt_error { if let Some(error) = opt_error {