fix: config merging
Embarrassingly, settings from the newly implemented config file where not being correctly applied. This *should* now be fixed. Change the show standard error default to true
This commit is contained in:
@@ -13,7 +13,7 @@
|
|||||||
// Show self (the oxker container) when running as a docker container
|
// Show self (the oxker container) when running as a docker container
|
||||||
"show_self": false,
|
"show_self": false,
|
||||||
// Show std_err in logs
|
// Show std_err in logs
|
||||||
"show_std_err": false,
|
"show_std_err": true,
|
||||||
// Show a timestamp for every log entry
|
// Show a timestamp for every log entry
|
||||||
"show_timestamp": true,
|
"show_timestamp": true,
|
||||||
// Don't draw gui - for debugging - mostly pointless
|
// Don't draw gui - for debugging - mostly pointless
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ raw_logs = false
|
|||||||
show_self = false
|
show_self = false
|
||||||
|
|
||||||
# Show std_err in logs
|
# Show std_err in logs
|
||||||
show_std_err = false
|
show_std_err = true
|
||||||
|
|
||||||
# Show a timestamp for every log entry
|
# Show a timestamp for every log entry
|
||||||
show_timestamp = true
|
show_timestamp = true
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ impl ContainerId {
|
|||||||
|
|
||||||
/// Only return first 8 chars of id, is usually more than enough for uniqueness
|
/// Only return first 8 chars of id, is usually more than enough for uniqueness
|
||||||
/// TODO container id is a hex string, so can assume that 0..=8 will always return a 8 char ascii &str
|
/// TODO container id is a hex string, so can assume that 0..=8 will always return a 8 char ascii &str
|
||||||
/// need to update tests to use real ids, or atleast strings of the correct-ish length
|
/// need to update tests to use real ids, or atleast strings of the correct-ish length
|
||||||
pub fn get_short(&self) -> String {
|
pub fn get_short(&self) -> String {
|
||||||
self.0.chars().take(8).collect::<String>()
|
self.0.chars().take(8).collect::<String>()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ raw_logs = false
|
|||||||
show_self = false
|
show_self = false
|
||||||
|
|
||||||
# Show std_err in logs
|
# Show std_err in logs
|
||||||
show_std_err = false
|
show_std_err = true
|
||||||
|
|
||||||
# Show a timestamp for every log entry
|
# Show a timestamp for every log entry
|
||||||
show_timestamp = true
|
show_timestamp = true
|
||||||
|
|||||||
+36
-14
@@ -126,19 +126,44 @@ impl Config {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Combine config from CLI into config file, the cli take priority
|
/// Combine config from CLI into config file, the cli take priority
|
||||||
/// make sure color_logs and raw_logs can't clash
|
/// and also make sure color_logs and raw_logs can't clash
|
||||||
fn merge_args(mut self, config_from_cli: Self) -> Self {
|
fn merge_args(mut self, config_from_cli: Self) -> Self {
|
||||||
self.color_logs = config_from_cli.color_logs;
|
let default_args = Args::default();
|
||||||
self.docker_interval_ms = config_from_cli.docker_interval_ms;
|
|
||||||
self.gui = config_from_cli.gui;
|
if config_from_cli.color_logs != default_args.color {
|
||||||
self.raw_logs = config_from_cli.raw_logs;
|
self.color_logs = config_from_cli.color_logs;
|
||||||
self.show_self = config_from_cli.show_self;
|
}
|
||||||
self.show_std_err = config_from_cli.show_std_err;
|
|
||||||
self.show_timestamp = config_from_cli.show_timestamp;
|
if config_from_cli.gui != default_args.gui {
|
||||||
self.use_cli = config_from_cli.use_cli;
|
self.gui = config_from_cli.gui;
|
||||||
|
}
|
||||||
|
|
||||||
|
if config_from_cli.docker_interval_ms != default_args.docker_interval {
|
||||||
|
self.docker_interval_ms = config_from_cli.docker_interval_ms;
|
||||||
|
}
|
||||||
|
|
||||||
if config_from_cli.docker_interval_ms < 1000 {
|
if config_from_cli.docker_interval_ms < 1000 {
|
||||||
self.docker_interval_ms = 1000;
|
self.docker_interval_ms = default_args.docker_interval;
|
||||||
|
}
|
||||||
|
|
||||||
|
if config_from_cli.raw_logs != default_args.raw {
|
||||||
|
self.raw_logs = config_from_cli.raw_logs;
|
||||||
|
}
|
||||||
|
|
||||||
|
if config_from_cli.show_self != default_args.show_self {
|
||||||
|
self.show_self = config_from_cli.show_self;
|
||||||
|
}
|
||||||
|
|
||||||
|
if config_from_cli.show_std_err != default_args.no_std_err {
|
||||||
|
self.show_std_err = config_from_cli.show_std_err;
|
||||||
|
}
|
||||||
|
|
||||||
|
if config_from_cli.show_timestamp != default_args.timestamp {
|
||||||
|
self.show_timestamp = config_from_cli.show_timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
if config_from_cli.use_cli != default_args.use_cli {
|
||||||
|
self.use_cli = config_from_cli.use_cli;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(host) = config_from_cli.host {
|
if let Some(host) = config_from_cli.host {
|
||||||
@@ -153,10 +178,7 @@ impl Config {
|
|||||||
self.timezone = Some(tz);
|
self.timezone = Some(tz);
|
||||||
}
|
}
|
||||||
|
|
||||||
if config_from_cli.raw_logs {
|
if self.color_logs && self.raw_logs {
|
||||||
self.color_logs = false;
|
|
||||||
}
|
|
||||||
if config_from_cli.color_logs {
|
|
||||||
self.raw_logs = false;
|
self.raw_logs = false;
|
||||||
}
|
}
|
||||||
self
|
self
|
||||||
|
|||||||
@@ -53,3 +53,22 @@ pub struct Args {
|
|||||||
#[clap(long="use-cli", short = None)]
|
#[clap(long="use-cli", short = None)]
|
||||||
pub use_cli: bool,
|
pub use_cli: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl Default for Args {
|
||||||
|
fn default() -> Self {
|
||||||
|
Self {
|
||||||
|
docker_interval: 1000,
|
||||||
|
timestamp: true,
|
||||||
|
color: false,
|
||||||
|
raw: false,
|
||||||
|
show_self: false,
|
||||||
|
gui: true,
|
||||||
|
host: None,
|
||||||
|
no_std_err: true,
|
||||||
|
timezone: None,
|
||||||
|
save_dir: None,
|
||||||
|
config_file: None,
|
||||||
|
use_cli: false,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -133,33 +133,13 @@ impl ConfigFile {
|
|||||||
Self::parse(file_type, &input)
|
Self::parse(file_type, &input)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Resolve conflict in the args, this is handled automatically by Clap, basically just by rejecting it
|
|
||||||
/// But here we can just change the options - although maybe should be also reject to follow the same behaviour as Clap?
|
|
||||||
/// TODO I think this is duplicated with the merge_args fn
|
|
||||||
fn resolve_conflict(&mut self) {
|
|
||||||
if let Some(color) = self.color_logs.as_ref() {
|
|
||||||
if *color {
|
|
||||||
self.raw_logs = Some(false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if let Some(interval) = self.docker_interval.as_ref() {
|
|
||||||
if interval < &1000 {
|
|
||||||
self.docker_interval = Some(1000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Try to parse the config file when the path is user supplied via cliargs
|
/// Try to parse the config file when the path is user supplied via cliargs
|
||||||
pub fn try_parse_from_file(path: &str) -> Option<Self> {
|
pub fn try_parse_from_file(path: &str) -> Option<Self> {
|
||||||
let path = PathBuf::from(path);
|
let path = PathBuf::from(path);
|
||||||
let Ok(file_type) = ConfigFileType::try_from(&path) else {
|
let Ok(file_type) = ConfigFileType::try_from(&path) else {
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
|
Self::parse_config_file(file_type, &path).ok()
|
||||||
Self::parse_config_file(file_type, &path).map_or(None, |mut config_file| {
|
|
||||||
config_file.resolve_conflict();
|
|
||||||
Some(config_file)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parse a config file using default config_file location
|
/// Parse a config file using default config_file location
|
||||||
@@ -172,11 +152,9 @@ impl ConfigFile {
|
|||||||
ConfigFileType::JsoncAsJson,
|
ConfigFileType::JsoncAsJson,
|
||||||
ConfigFileType::Json,
|
ConfigFileType::Json,
|
||||||
] {
|
] {
|
||||||
if let Ok(mut config_file) =
|
if let Ok(config_file) =
|
||||||
Self::parse_config_file(file_type, &file_type.get_default_path_name(in_container))
|
Self::parse_config_file(file_type, &file_type.get_default_path_name(in_container))
|
||||||
{
|
{
|
||||||
Self::resolve_conflict(&mut config_file);
|
|
||||||
|
|
||||||
config = Some(config_file);
|
config = Some(config_file);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -475,8 +475,8 @@ mod tests {
|
|||||||
|
|
||||||
assert_snapshot!(setup.terminal.backend());
|
assert_snapshot!(setup.terminal.backend());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
/// Custom keymap for help panel is correctly display, two definitions
|
/// Custom keymap for help panel is correctly display, two definitions
|
||||||
fn test_draw_blocks_headers_custom_keymap_two_definitions() {
|
fn test_draw_blocks_headers_custom_keymap_two_definitions() {
|
||||||
let mut setup = test_setup(140, 1, true, true);
|
let mut setup = test_setup(140, 1, true, true);
|
||||||
|
|||||||
Reference in New Issue
Block a user