Skip to content

Commit

Permalink
Add some checks in log searching
Browse files Browse the repository at this point in the history
  • Loading branch information
andrew121410 committed Apr 24, 2024
1 parent 135193f commit e466956
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion src/log_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::env::temp_dir;
use std::fs;
use std::fs::{File, OpenOptions};
use std::io::{BufRead, BufReader, Read, Write};
use std::path::{PathBuf};
use std::path::PathBuf;
use std::process::{Command, exit, Stdio};
use std::time::{Duration, SystemTime};

Expand All @@ -25,6 +25,12 @@ impl LogSearch {
}

pub fn context(&self, lines_before: u64, lines_after: u64) {
// See if the logs directory exists
if !self.logs_dir.exists() {
eprintln!("{}", format!("We couldn't find the logs directory at {}. Exiting...", self.logs_dir.display()).red());
exit(1);
}

// Create a temporary directory inside the "logs" folder to hold the log files
let temp_dir_in_logs_folder = self.logs_dir.join(".lmtmp");
fs::create_dir(&temp_dir_in_logs_folder).unwrap_or_else(|e| {
Expand Down Expand Up @@ -148,6 +154,14 @@ impl LogSearch {
eprintln!("Error deleting directory: {}", e);
});

// Check if the txt file exists
let file_path = temp_dir().join("limonium-log-search.txt");
if !file_path.exists() {
println!("{}", format!("We searched for {}", self.to_search.as_str()).bright_yellow());
println!("{}", "No matching lines found in the logs. Exiting...".red());
return;
}

// Open the file in nano
self.open_in_nano();

Expand Down

0 comments on commit e466956

Please sign in to comment.