Skip to content
Snippets Groups Projects
Commit 619f937d authored by Steve Purcell's avatar Steve Purcell
Browse files

Support input from stdin

Closes #2.
parent 2fe6381b
No related branches found
No related tags found
No related merge requests found
......@@ -7,7 +7,7 @@ require 'optparse'
options = { limit: 1000 }
optparse = OptionParser.new do |opts|
opts.banner = "Usage: #{File.basename($0)} [options] file.sql ..."
opts.banner = "Usage: #{File.basename($0)} [options] [file.sql ...]"
opts.separator ""
opts.separator "Options:"
opts.on("--limit=N", Integer, "Limit checking to N errors (default: #{options[:limit]})") do |n|
......@@ -23,10 +23,6 @@ optparse = OptionParser.new do |opts|
end
end
optparse.parse!(ARGV)
if ARGV.empty?
puts optparse
exit 1
end
ERROR_TYPES = {error: "ERROR", warning: "WARNING"}
......@@ -51,15 +47,25 @@ def display_lint(lint)
end
end
saw_errors = false
def each_input_file(&block)
if ARGV.empty?
yield [STDIN, "stdin"]
else
ARGV.each do |filename|
File.open(filename, 'r') do |file|
yield [file, filename]
end
end
end
end
saw_errors = false
each_input_file do |file, filename|
results = SQLint::Linter.new(filename, file).run.first(options[:limit])
results.each do |lint|
display_lint(lint)
end
saw_errors ||= results.any? { |lint| lint.type == :error }
end
end
exit 1 if saw_errors
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment