From c81a2bd80ef827d1cdacf75d3770f29ccf196cb4 Mon Sep 17 00:00:00 2001 From: diogo464 Date: Thu, 26 Jun 2025 16:23:49 +0100 Subject: Refactor cat and tail flag logic for better readability MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the cryptic boolean expressions with clearer if-else logic that explicitly handles the flag combinations: Old logic (functionally correct but hard to understand): let show_stdout = !args.stderr || args.stdout; let show_stderr = !args.stdout || args.stderr; New logic (clear and self-documenting): let show_stdout = if args.stdout || args.stderr { args.stdout } else { true // Show both when no flags are specified }; This change improves code readability while maintaining identical behavior: - No flags: show both stdout and stderr - --stdout only: show only stdout - --stderr only: show only stderr - Both flags: show both stdout and stderr 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- src/main.rs | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) (limited to 'src/main.rs') diff --git a/src/main.rs b/src/main.rs index 9bb8d24..2a0510e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -290,8 +290,19 @@ fn run_command(command: Commands) -> Result<()> { stop_daemon(&args.id, args.timeout, &root_dir) } Commands::Tail(args) => { - let show_stdout = !args.stderr || args.stdout; - let show_stderr = !args.stdout || args.stderr; + // Clearer logic for determining which streams to show: + // - If no flags are specified, show both streams + // - If one or both flags are specified, show only the requested streams + let show_stdout = if args.stdout || args.stderr { + args.stdout + } else { + true // Show both when no flags are specified + }; + let show_stderr = if args.stdout || args.stderr { + args.stderr + } else { + true // Show both when no flags are specified + }; let root_dir = resolve_root_dir(&args.global)?; tail_logs( &args.id, @@ -303,8 +314,19 @@ fn run_command(command: Commands) -> Result<()> { ) } Commands::Cat(args) => { - let show_stdout = !args.stderr || args.stdout; - let show_stderr = !args.stdout || args.stderr; + // Clearer logic for determining which streams to show: + // - If no flags are specified, show both streams + // - If one or both flags are specified, show only the requested streams + let show_stdout = if args.stdout || args.stderr { + args.stdout + } else { + true // Show both when no flags are specified + }; + let show_stderr = if args.stdout || args.stderr { + args.stderr + } else { + true // Show both when no flags are specified + }; let root_dir = resolve_root_dir(&args.global)?; cat_logs(&args.id, show_stdout, show_stderr, &root_dir) } -- cgit