diff --git a/bin/csv-filter b/bin/csv-filter index 9b44b481..3b830df0 100755 --- a/bin/csv-filter +++ b/bin/csv-filter @@ -22,7 +22,7 @@ parser.on('--input-col-sep=SEPARATOR', options[:input_col_sep] = value end -parser.on('--input-quote-char=SEPARATOR', +parser.on('--input-quote-char=CHAR', 'Input quote character.') do |value| options[:input_quote_char] = value end @@ -37,7 +37,7 @@ parser.on('--output-col-sep=SEPARATOR', options[:output_col_sep] = value end -parser.on('--output-quote-char=SEPARATOR', +parser.on('--output-quote-char=CHAR', 'Output quote character.') do |value| options[:output_quote_char] = value end @@ -52,6 +52,11 @@ parser.on('-r', '--row-sep=SEPARATOR', options[:row_sep] = value end +parser.on('-c', '--col-sep=SEPARATOR', + 'Column separator string.') do |value| + options[:col_sep] = value +end + begin parser.parse! rescue OptionParser::InvalidOption diff --git a/test/csv/test_csv_filter.rb b/test/csv/test_csv_filter.rb index 4d356db4..2722806c 100644 --- a/test/csv/test_csv_filter.rb +++ b/test/csv/test_csv_filter.rb @@ -127,4 +127,14 @@ def test_option_row_sep assert_equal(["aaa,bbb,ccc.ddd,eee,fff.", ""], run_csv_filter(csv, "--row-sep=:", "--output-row-sep=.")) end + + def test_option_col_sep + csv = "aaa:bbb:ccc\nddd:eee:fff\n" + assert_equal(["aaa:bbb:ccc\nddd:eee:fff\n", ""], + run_csv_filter(csv, "--col-sep=:")) + assert_equal(["aaa.bbb.ccc\nddd.eee.fff\n", ""], + run_csv_filter(csv, "--col-sep=.", "--input-col-sep=:")) + assert_equal(["aaa.bbb.ccc\nddd.eee.fff\n", ""], + run_csv_filter(csv, "--col-sep=:", "--output-col-sep=.")) + end end