Sha256: 33f3420a05478c36bc8f9a51055bdc2bec8e0f3ba59a5764ddee6cb24393b139

Contents?: true

Size: 861 Bytes

Versions: 1

Compression:

Stored size: 861 Bytes

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 = "Usage: csvsql [options] SQL"

  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('--clear-cache', "Clear all cache data") do
    options[:clear_cache] = true
  end
end.parse!

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

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

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
csvsql-0.1.0 exe/csvsql