diff options
| author | diogo464 <[email protected]> | 2025-06-26 16:23:49 +0100 |
|---|---|---|
| committer | diogo464 <[email protected]> | 2025-06-26 16:23:49 +0100 |
| commit | c81a2bd80ef827d1cdacf75d3770f29ccf196cb4 (patch) | |
| tree | d386c9ae655ac804b61cbf60673dd87d5d245560 /src | |
| parent | 102cbbbf38e43657779ecd637f5a2518801f1cae (diff) | |
Refactor cat and tail flag logic for better readabilityfix-tail-flag-logic
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 <[email protected]>
Diffstat (limited to 'src')
| -rw-r--r-- | src/main.rs | 30 |
1 files changed, 26 insertions, 4 deletions
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<()> { | |||
| 290 | stop_daemon(&args.id, args.timeout, &root_dir) | 290 | stop_daemon(&args.id, args.timeout, &root_dir) |
| 291 | } | 291 | } |
| 292 | Commands::Tail(args) => { | 292 | Commands::Tail(args) => { |
| 293 | let show_stdout = !args.stderr || args.stdout; | 293 | // Clearer logic for determining which streams to show: |
| 294 | let show_stderr = !args.stdout || args.stderr; | 294 | // - If no flags are specified, show both streams |
| 295 | // - If one or both flags are specified, show only the requested streams | ||
| 296 | let show_stdout = if args.stdout || args.stderr { | ||
| 297 | args.stdout | ||
| 298 | } else { | ||
| 299 | true // Show both when no flags are specified | ||
| 300 | }; | ||
| 301 | let show_stderr = if args.stdout || args.stderr { | ||
| 302 | args.stderr | ||
| 303 | } else { | ||
| 304 | true // Show both when no flags are specified | ||
| 305 | }; | ||
| 295 | let root_dir = resolve_root_dir(&args.global)?; | 306 | let root_dir = resolve_root_dir(&args.global)?; |
| 296 | tail_logs( | 307 | tail_logs( |
| 297 | &args.id, | 308 | &args.id, |
| @@ -303,8 +314,19 @@ fn run_command(command: Commands) -> Result<()> { | |||
| 303 | ) | 314 | ) |
| 304 | } | 315 | } |
| 305 | Commands::Cat(args) => { | 316 | Commands::Cat(args) => { |
| 306 | let show_stdout = !args.stderr || args.stdout; | 317 | // Clearer logic for determining which streams to show: |
| 307 | let show_stderr = !args.stdout || args.stderr; | 318 | // - If no flags are specified, show both streams |
| 319 | // - If one or both flags are specified, show only the requested streams | ||
| 320 | let show_stdout = if args.stdout || args.stderr { | ||
| 321 | args.stdout | ||
| 322 | } else { | ||
| 323 | true // Show both when no flags are specified | ||
| 324 | }; | ||
| 325 | let show_stderr = if args.stdout || args.stderr { | ||
| 326 | args.stderr | ||
| 327 | } else { | ||
| 328 | true // Show both when no flags are specified | ||
| 329 | }; | ||
| 308 | let root_dir = resolve_root_dir(&args.global)?; | 330 | let root_dir = resolve_root_dir(&args.global)?; |
| 309 | cat_logs(&args.id, show_stdout, show_stderr, &root_dir) | 331 | cat_logs(&args.id, show_stdout, show_stderr, &root_dir) |
| 310 | } | 332 | } |
