#!/usr/bin/env ruby # for dev purposes require 'bundler/setup' if ENV['HONEY_FORMAT_GEM_DEV'] require 'honey_format' require 'honey_format/cli/cli' cli = HoneyFormat::CLI.new options = cli.options input_path = options[:input_path] || raise(ArgumentError, 'input path required') csv_input = File.read(input_path) csv = HoneyFormat::CSV.new( csv_input, delimiter: options[:delimiter], type_map: options[:type_map], skip_lines: options[:skip_lines] ) csv_part = if options[:header_only] csv.header elsif options[:rows_only] csv.rows else csv end csv_string = csv_part.to_csv(columns: options[:columns]) if path = options[:output_path] File.write(path, csv_string) else puts csv_string end