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'
|
if args[0] == '--parse' || args[0] == '-p'
|
||||||
puts("[!] Opening log file at #{args[1]}")
|
puts("[!] Opening log file at #{args[1]}")
|
||||||
|
|
||||||
|
begin
|
||||||
logfile = File.open(args[1])
|
logfile = File.open(args[1])
|
||||||
|
rescue Errno::ENOENT
|
||||||
|
warn "[x] The file #{args[1]} was not found."
|
||||||
|
exit 1
|
||||||
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
puts('[!] Log file path not provided, assuming default access.log')
|
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
|
end
|
||||||
|
|
||||||
data = logfile.read
|
data = logfile.read
|
||||||
|
|
Loading…
Reference in New Issue