From 8182119426a0fab2a68ead695d5cb111c2653bfe Mon Sep 17 00:00:00 2001 From: Miguel Nogueira Date: Sun, 19 May 2024 17:48:02 +0100 Subject: [PATCH] feat(args): improve file open logic --- main.rb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/main.rb b/main.rb index 07d9580..ff4d13e 100644 --- a/main.rb +++ b/main.rb @@ -8,10 +8,24 @@ args = ARGV if args[0] == '--parse' || args[0] == '-p' puts("[!] Opening log file at #{args[1]}") - logfile = File.open(args[1]) + + begin + logfile = File.open(args[1]) + rescue Errno::ENOENT + warn "[x] The file #{args[1]} was not found." + exit 1 + end + else puts('[!] Log file path not provided, assuming default access.log') - logfile = File.open('access.log', 'a') + + begin + logfile = File.open('access.log') + rescue Errno::ENOENT + warn '[x] Default file access.log not found. Specify an alternative log file to parse with -p or --parse.' + exit 1 + end + end data = logfile.read