Sha256: 1576212aec46189fba69007fec23372f85479b6fef1c3116d45e26520ac95432

Contents?: true

Size: 1.27 KB

Versions: 2

Compression:

Stored size: 1.27 KB

Contents

#! /usr/bin/env ruby

require 'optparse'

lib = File.expand_path("../../lib", __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'csvsql'

options = {}
OptionParser.new do |opts|
  opts.banner = "Csvsql #{Csvsql::VERSION}\nUsage: csvsql [options] SQL"
  opts.version = Csvsql::VERSION

  opts.on('-i', '--input path', "CSV file path, optional. read from stdin if no give") do |path|
    options[:csv_path] = path
  end

  opts.on('-c', '--use-cache', "Cache data in ~/.csvsql_cache. it will still reload if file was changed") do
    options[:use_cache] = true
  end

  opts.on(
    '-b', '--batch-rows n',
    "How many rows to import per batch. Default value is #{Csvsql::Db::BATCH_ROWS}"
  ) do |n|
    options[:batch_rows] = n.to_i
  end

  opts.on('--clear-cache', "Clear all cache data") do
    options[:clear_cache] = true
  end

  opts.on('--debug', "Print debug info") do
    options[:debug] = true
  end
end.parse!

if options[:clear_cache]
  Csvsql::Db.clear_cache!
  puts "Completed clear cache."
  exit
end

if options[:debug]
  Csvsql::Tracker.tracker = Csvsql::Tracker.new(Logger.new($stdout))
end

csv_data = options[:csv_path] || StringIO.new($stdin.read)

puts Csvsql.execute(ARGV[0], csv_data, use_cache: options[:use_cache], batch_rows: options[:batch_rows])

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
csvsql-0.1.2 exe/csvsql
csvsql-0.1.1 exe/csvsql