Skip to content

Commit 7eea19a

Browse files
BurdetteLamarkou
andauthored
csv-filter: add --col-sep (#338)
Also corrects help text for --*-quote-char (changes SEPARATOR to CHAR). --------- Co-authored-by: Sutou Kouhei <kou@cozmixng.org>
1 parent a66c40f commit 7eea19a

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

bin/csv-filter

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ parser.on('--input-col-sep=SEPARATOR',
2222
options[:input_col_sep] = value
2323
end
2424

25-
parser.on('--input-quote-char=SEPARATOR',
25+
parser.on('--input-quote-char=CHAR',
2626
'Input quote character.') do |value|
2727
options[:input_quote_char] = value
2828
end
@@ -37,7 +37,7 @@ parser.on('--output-col-sep=SEPARATOR',
3737
options[:output_col_sep] = value
3838
end
3939

40-
parser.on('--output-quote-char=SEPARATOR',
40+
parser.on('--output-quote-char=CHAR',
4141
'Output quote character.') do |value|
4242
options[:output_quote_char] = value
4343
end
@@ -52,6 +52,11 @@ parser.on('-r', '--row-sep=SEPARATOR',
5252
options[:row_sep] = value
5353
end
5454

55+
parser.on('-c', '--col-sep=SEPARATOR',
56+
'Column separator string.') do |value|
57+
options[:col_sep] = value
58+
end
59+
5560
begin
5661
parser.parse!
5762
rescue OptionParser::InvalidOption

test/csv/test_csv_filter.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,4 +127,14 @@ def test_option_row_sep
127127
assert_equal(["aaa,bbb,ccc.ddd,eee,fff.", ""],
128128
run_csv_filter(csv, "--row-sep=:", "--output-row-sep=."))
129129
end
130+
131+
def test_option_col_sep
132+
csv = "aaa:bbb:ccc\nddd:eee:fff\n"
133+
assert_equal(["aaa:bbb:ccc\nddd:eee:fff\n", ""],
134+
run_csv_filter(csv, "--col-sep=:"))
135+
assert_equal(["aaa.bbb.ccc\nddd.eee.fff\n", ""],
136+
run_csv_filter(csv, "--col-sep=.", "--input-col-sep=:"))
137+
assert_equal(["aaa.bbb.ccc\nddd.eee.fff\n", ""],
138+
run_csv_filter(csv, "--col-sep=:", "--output-col-sep=."))
139+
end
130140
end

0 commit comments

Comments
 (0)