#!/usr/bin/env ruby

require 'optparse'
require 'csv'

options = {}

parser = OptionParser.new

parser.version = CSV::VERSION
parser.banner = <<-BANNER
Usage: #{parser.program_name} [options]

  Reads and parses the CSV text content of the standard input per the given input options.
  From that content, generates CSV text per the given output options
  and writes that text to the standard output.
BANNER


parser.on('--input-col-sep=SEPARATOR',
          'Input column separator string.') do |value|
  options[:input_col_sep] = value
end

parser.on('--input-quote-char=SEPARATOR',
          'Input quote character.') do |value|
  options[:input_quote_char] = value
end

parser.on('--input-row-sep=SEPARATOR',
          'Input row separator string.') do |value|
  options[:input_row_sep] = value
end

parser.on('--output-col-sep=SEPARATOR',
          'Output column separator string.') do |value|
  options[:output_col_sep] = value
end

parser.on('--output-row-sep=SEPARATOR',
          'Output row separator string.') do |value|
  options[:output_row_sep] = value
end

parser.on('-r', '--row-sep=SEPARATOR',
          'Row separator string.') do |value|
  options[:row_sep] = value
end

begin
  parser.parse!
rescue OptionParser::InvalidOption
  $stderr.puts($!.message)
  $stderr.puts(parser)
  exit(false)
end

CSV.filter(**options) do |row|
end
