diff --git a/bin/csv-filter b/bin/csv-filter index 8eddc538..8f273984 100755 --- a/bin/csv-filter +++ b/bin/csv-filter @@ -22,6 +22,11 @@ parser.on('--input-col-sep=SEPARATOR', 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 diff --git a/test/csv/test_csv_filter.rb b/test/csv/test_csv_filter.rb index dc9f432a..bbe13910 100644 --- a/test/csv/test_csv_filter.rb +++ b/test/csv/test_csv_filter.rb @@ -78,6 +78,21 @@ def test_option_input_col_sep run_csv_filter(csv, "--input-col-sep=:")) end + def test_option_input_quote_char + input_quote_char = "'" + csv_text = CSV.generate(quote_char: input_quote_char) do |csv| + csv << ['foo', 0] + csv << ["'bar'", 1] + csv << ['"baz"', 2] + end + expected = <<-EXPECTED +foo,0 +'bar',1 +"""baz""",2 + EXPECTED + assert_equal([expected, ""], run_csv_filter(csv_text, "--input-quote-char=#{input_quote_char}")) + end + def test_option_input_row_sep csv = "aaa,bbb,ccc:ddd,eee,fff:" assert_equal(["aaa,bbb,ccc\nddd,eee,fff\n", ""],