From c739637b91c8fa742a69f4d888678d7b3964678c Mon Sep 17 00:00:00 2001 From: Jack Wills <32690432+mrjackwills@users.noreply.github.com> Date: Tue, 3 Dec 2024 15:01:56 +0000 Subject: [PATCH] feat: `--no-stderr` cli arg, closes #52 New cli argument which will remove stderr output from logs, defaults to false --- CHANGELOG.md | 2 +- README.md | 1 + src/app_data/mod.rs | 1 + src/docker_data/mod.rs | 7 +++++-- src/main.rs | 1 + src/parse_args.rs | 12 +++++++++--- src/ui/mod.rs | 1 + 7 files changed, 19 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 38447fa..bbbe1bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,7 +16,7 @@ + help_box closure fn, [2860426d57a4458fcee49a2fd20e8e7bb9e71fb5] + use check_sub for sleep calculations, [fe3696e5576739d8b033d9e748b5ea696c4b4e4f] + rename scheduler to heartbeat, [68a6551ed038a36330b2f098112829465a1c3c7a] -+ remove uneccessary is_running load, [76ccf7c00691f815c3ab0bede838c99252ba84f0] ++ remove unnecessary is_running load, [76ccf7c00691f815c3ab0bede838c99252ba84f0] + execute_command(), [2a834d6c2fa4a15124d24ddbd12f667829e148ad] diff --git a/README.md b/README.md index 49c2938..b239e57 100644 --- a/README.md +++ b/README.md @@ -127,6 +127,7 @@ Available command line arguments |```-s```| If running via Docker, will display the oxker container.| |```-g```| No TUI, essentially a debugging mode with limited functionality, for now.| |```--host [string]```| Connect to Docker with a custom hostname. Defaults to `/var/run/docker.sock`. Will use `$DOCKER_HOST` environment variable if set.| +|```--no-stderr```| Do not include stderr output in logs.| |```--save-dir [string]```| Save exported logs into a custom directory. Defaults to `$HOME`.| |```--use-cli```| Use the Docker application when exec-ing into a container, instead of the Docker API.| diff --git a/src/app_data/mod.rs b/src/app_data/mod.rs index 2907570..f0f05f1 100644 --- a/src/app_data/mod.rs +++ b/src/app_data/mod.rs @@ -442,6 +442,7 @@ impl AppData { } /// Find the longest port when it's transformed into a string, defaults are header lens (ip, private, public) + /// TODO refactor this, and write comments as to whete the initial sizes come from pub fn get_longest_port(&self) -> (usize, usize, usize) { let mut longest_ip = 5; let mut longest_private = 10; diff --git a/src/docker_data/mod.rs b/src/docker_data/mod.rs index 1188b84..9a42b99 100644 --- a/src/docker_data/mod.rs +++ b/src/docker_data/mod.rs @@ -253,10 +253,11 @@ impl DockerData { init: Option>, since: u64, spawns: Arc>>>, + stderr: bool, ) { let options = Some(LogsOptions:: { stdout: true, - stderr: true, + stderr, timestamps: true, since: i64::try_from(since).unwrap_or_default(), ..Default::default() @@ -289,6 +290,7 @@ impl DockerData { init.map(Arc::clone), 0, Arc::clone(&self.spawns), + self.args.std_err, )), ); } @@ -330,6 +332,7 @@ impl DockerData { None, last_updated, Arc::clone(&self.spawns), + self.args.std_err, )) }); }; @@ -348,7 +351,7 @@ impl DockerData { .set_error(AppError::DockerCommand(error), gui_state, Status::Error); } - /// Execute docker comamnds (start, stop etc) on it's own tokio thread + /// Execute docker commands (start, stop etc) on it's own tokio thread async fn execute_command(&mut self, control: DockerCommand, id: ContainerId) { let (app_data, docker, gui_state) = ( Arc::clone(&self.app_data), diff --git a/src/main.rs b/src/main.rs index 2ab1d17..3ad0af4 100644 --- a/src/main.rs +++ b/src/main.rs @@ -164,6 +164,7 @@ mod tests { docker_interval: 1000, gui: true, host: None, + std_err: false, in_container: false, save_dir: None, raw: false, diff --git a/src/parse_args.rs b/src/parse_args.rs index c1cb998..911ba20 100644 --- a/src/parse_args.rs +++ b/src/parse_args.rs @@ -37,13 +37,17 @@ pub struct Args { #[clap(long, short = None)] pub host: Option, - /// Force use of docker cli when execing into containers - #[clap(long="use-cli", short = None)] - pub use_cli: bool, + /// Do not include stderr output in logs + #[clap(long = "no-stderr")] + pub no_std_err: bool, /// Directory for saving exported logs, defaults to `$HOME` #[clap(long="save-dir", short = None)] pub save_dir: Option, + + /// Force use of docker cli when execing into containers + #[clap(long="use-cli", short = None)] + pub use_cli: bool, } #[derive(Debug, Clone)] @@ -58,6 +62,7 @@ pub struct CliArgs { pub raw: bool, pub show_self: bool, pub timestamp: bool, + pub std_err: bool, pub use_cli: bool, } @@ -92,6 +97,7 @@ impl CliArgs { in_container: Self::check_if_in_container(), save_dir: logs_dir, raw: args.raw, + std_err: !args.no_std_err, show_self: !args.show_self, timestamp: !args.timestamp, } diff --git a/src/ui/mod.rs b/src/ui/mod.rs index b0e7fef..9c209e0 100644 --- a/src/ui/mod.rs +++ b/src/ui/mod.rs @@ -220,6 +220,7 @@ impl Ui { } /// Frequent data required by multiple framde drawing functions, can reduce mutex reads by placing it all in here +/// TODO add more items to this, and split up into parts #[derive(Debug)] pub struct FrameData { columns: Columns,