Sha256: a4ed86456bbebd941ff9d138b70e60aff6187dd9636a5c149c2c0ce62e98cd35
Contents?: true
Size: 1.39 KB
Versions: 2
Compression:
Stored size: 1.39 KB
Contents
#!/usr/bin/env ruby require "rubygems" require 'optparse' require 'ostruct' require File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'csv2json.rb') # this form is important for local development module CSV2JSONRunner # command-line parsing COMMAND = File.basename($0) USAGE = "Usage: #{COMMAND} [INPUT] [OPTIONS]" options = OpenStruct.new options.output = "-" opts = OptionParser.new do |o| o.banner = USAGE o.separator "" o.separator "Specific options:" o.on("-o", "--output FILE", "Write output to a file") do |fn| options.output = fn end o.on_tail("-h", "--help", "Show this message") do puts o exit end o.on_tail("-v", "--version", "Show version") do puts CSV2JSON::VERSION exit end end begin opts.parse!(ARGV) rescue die "Unable to parse options: #{$!}" end # initialize output handle if options.output == "-" OUT = $stdout.clone else OUT = File.open(options.output, "w") end if ARGV.size > 0 IN = File.open(ARGV[0], "r") else IN = StringIO.new($stdin.read) # cannot be just $stdin.clone because FasterCSV is seeking in file :-( end # run the command CSV2JSON.parse(IN, OUT) # leave in peace OUT.flush end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
csv2json-0.1.1 | bin/csv2json |
csv2json-0.1.0 | bin/csv2json |