feat(args): improve file open logic

This commit is contained in:
Miguel Nogueira 2024-05-19 17:48:02 +01:00
parent 4cd97100eb
commit 8182119426
Signed by: miguel456
GPG Key ID: 43EF15DB0CC86DDD
1 changed files with 16 additions and 2 deletions

16
main.rb
View File

@ -8,10 +8,24 @@ args = ARGV
if args[0] == '--parse' || args[0] == '-p'
puts("[!] Opening log file at #{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