feat(args): improve file open logic
This commit is contained in:
parent
4cd97100eb
commit
8182119426
16
main.rb
16
main.rb
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue