91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
|
# File 'lib/ultragrep.rb', line 91
def parse_args(argv)
options = {
:files => [],
:range_start => Time.now.to_i - (Time.now.to_i % DAY),
:range_end => Time.now.to_i,
}
key_value = []
warn_about_missing_quotes_in_time_argument(argv)
parser = OptionParser.new do |parser|
parser.banner = <<-BANNER.gsub(/^ {6,}/, "")
Usage: ultragrep [OPTIONS] [REGEXP ...]
Dates: all datetimes are in UTC whatever Ruby's Time.parse() accepts.
For example '2011-04-30 11:30:00'.
Options are:
BANNER
parser.on("--help", "-h", "This text"){ puts parser; exit 0 }
parser.on("--version", "Show version") do
require 'ultragrep/version'
puts "Ultragrep version #{Ultragrep::VERSION}"
exit 0
end
parser.on("--config", "-c FILE", String, "Config file location (default: #{Config::DEFAULT_LOCATIONS.join(", ")})") { |config| options[:config] = config }
parser.on("--progress", "-p", "show grep progress to STDERR") { options[:verbose] = true }
parser.on("--verbose", "-v", "DEPRECATED") do
$stderr.puts("The --verbose option is gone. please use -p or --progress instead")
exit 0
end
parser.on("--not REGEXP", "the next given regular expression's match status should invert") do |regexp|
options[:not_regexps] ||= []
options[:not_regexps] << regexp
end
parser.on("--tail", "-t", "Tail requests, show matching requests as they arrive") do
options[:tail] = true
options[:range_end] = Time.now.to_i + 100 * DAY
end
parser.on("--type", "-l TYPE", String, "Search type of logs, specified in config") { |type| options[:type] = type }
parser.on("--perf", "Output just performance information") { options[:perf] = true }
parser.on("--day", "-d DATETIME", String, "Find requests that happened on this day") do |date|
date = parse_time(date)
options[:range_start] = date
options[:range_end] = date + DAY - 1
end
parser.on("--daysback", "-b COUNT", Integer, "Find requests from COUNT days ago to now") do |back|
options[:range_start] = Time.now.to_i - (back * DAY)
end
parser.on("--hoursback", "-o COUNT", Integer, "Find requests from COUNT hours ago to now") do |back|
options[:range_start] = Time.now.to_i - (back * HOUR)
end
parser.on("--start", "-s DATETIME", String, "Find requests starting at this date") do |date|
options[:range_start] = parse_time(date)
end
parser.on("--end", "-e DATETIME", String, "Find requests ending at this date") do |date|
options[:range_end] = parse_time(date)
end
parser.on("--around DATETIME", String, "Find a request at about this time (10 seconds buffer on either side") do |date|
options[:range_start] = parse_time(date) - 10
options[:range_end] = parse_time(date) + 10
end
parser.on("--host HOST", String, "Only find requests on this host") do |host|
options[:host_filter] ||= []
options[:host_filter] << host
end
end
parser.parse!(argv)
if argv.empty?
puts parser
exit 1
else
options[:regexps] = argv
end
options[:printer] = if options.delete(:perf)
RequestPerformancePrinter.new(options[:verbose])
else
RequestPrinter.new(options[:verbose])
end
options[:config] = load_config(options[:config])
options
end
|