1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
use clap::Parser;
use log_watcher::cli::Args;
use log_watcher::config::Config;
use log_watcher::watcher::LogWatcher;
use std::process;
use tracing::{error, info};
#[tokio::main]
async fn main() {
// Initialize logging
tracing_subscriber::fmt::init();
let args = Args::parse();
// Handle shell completions generation
if let Some(shell) = args.completions {
Args::generate_completions(shell);
process::exit(0);
}
// Build configuration from CLI args
let config = match Config::from_args(&args) {
Ok(config) => config,
Err(e) => {
eprintln!("Configuration error: {}", e);
process::exit(2);
}
};
// Create and run the log watcher
let mut watcher = LogWatcher::new(config);
match watcher.run().await {
Ok(_) => {
info!("LogWatcher completed successfully");
process::exit(0);
}
Err(e) => {
error!("LogWatcher failed: {}", e);
process::exit(1);
}
}
}
#[cfg(test)]
mod tests {
use std::process::Command;
#[test]
fn test_main_with_invalid_args() {
// Test that main handles invalid arguments gracefully
let output = Command::new("cargo")
.args(["run", "--", "--invalid-flag"])
.output()
.expect("Failed to execute command");
// Should exit with non-zero code for invalid args
assert!(!output.status.success());
}
#[test]
fn test_config_error_handling_coverage_lines_19_20() {
// Test configuration error handling to cover lines 19-20
// This test verifies that configuration errors are handled properly
// We can't easily test the actual exit(2) call, but we can test the error path
let output = Command::new("cargo")
.args([
"run",
"--",
"--files",
"/nonexistent/file.log",
"--patterns",
"ERROR",
])
.output()
.expect("Failed to execute command");
// Should exit with error code due to file not found
assert!(!output.status.success());
}
#[test]
fn test_logwatcher_error_handling_coverage_line_34() {
// Test LogWatcher error handling to cover line 34
// This test verifies that LogWatcher errors are handled properly
let output = Command::new("cargo")
.args([
"run",
"--",
"--files",
"/nonexistent/file.log",
"--patterns",
"ERROR",
])
.output()
.expect("Failed to execute command");
// Should exit with error code due to file not found
assert!(!output.status.success());
}
}