From 87be5b0d59a4a454423d92aea2ccf2d6a17ec40c Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Sat, 22 Mar 2025 11:41:10 -0500 Subject: [PATCH 1/2] csv-filter: add --col-sep --- bin/csv-filter | 9 +++++++-- test/csv/test_csv_filter.rb | 10 ++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) 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..2d3c50f3 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\n" + "ddd.eee.fff\n", ""], + run_csv_filter(csv, "--col-sep=.", "--input-col-sep=:")) + assert_equal(["aaa.bbb.ccc\n" + "ddd.eee.fff\n", ""], + run_csv_filter(csv, "--col-sep=:", "--output-col-sep=.")) + end end From df1019c39f21821b674124d33771c9d1a215ce1a Mon Sep 17 00:00:00 2001 From: Sutou Kouhei Date: Sun, 23 Mar 2025 09:38:14 +0900 Subject: [PATCH 2/2] Remove needless + --- test/csv/test_csv_filter.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/csv/test_csv_filter.rb b/test/csv/test_csv_filter.rb index 2d3c50f3..2722806c 100644 --- a/test/csv/test_csv_filter.rb +++ b/test/csv/test_csv_filter.rb @@ -132,9 +132,9 @@ 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\n" + "ddd.eee.fff\n", ""], + assert_equal(["aaa.bbb.ccc\nddd.eee.fff\n", ""], run_csv_filter(csv, "--col-sep=.", "--input-col-sep=:")) - assert_equal(["aaa.bbb.ccc\n" + "ddd.eee.fff\n", ""], + assert_equal(["aaa.bbb.ccc\nddd.eee.fff\n", ""], run_csv_filter(csv, "--col-sep=:", "--output-col-sep=.")) end end