Skip to content

Commit

Permalink
Added simple command-line tool as example
Browse files Browse the repository at this point in the history
  • Loading branch information
ldodds committed Feb 4, 2014
1 parent bddbb80 commit 9e51b04
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
39 changes: 39 additions & 0 deletions bin/csvlint
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#!/usr/bin/env ruby
$:.unshift File.join( File.dirname(__FILE__), "..", "lib")

require 'csvlint'
require 'colorize'

def print_error(index, error, color=:red)
location = ""
location += error.row.to_s if error.row
location += "#{error.row ? "," : ""}#{error.column.to_s}" if error.column
if error.row || error.column
location = "#{error.row ? "Row" : "Column"}: #{location}"
end
puts "#{index+1}. #{error.type}. #{location}".colorize(color)
end

if ARGV.length == 0
puts "Usage: csvlint <filename|url>"
exit 1
end

source = ARGV[0]
source = File.new( source ) unless source =~ /^http(s)?/

validator = Csvlint::Validator.new( source )

puts "#{ARGV[0]} is #{validator.valid? ? "VALID".green : "INVALID".red}"

if validator.errors.size > 0
validator.errors.each_with_index do |error, i|
print_error(i, error)
end
end

if validator.warnings.size > 0
validator.warnings.each_with_index do |error, i|
print_error(i, error, :yellow)
end
end
1 change: 1 addition & 0 deletions csvlint.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]

spec.add_dependency "mime-types"
spec.add_dependency "colorize"

spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake"
Expand Down

0 comments on commit 9e51b04

Please sign in to comment.