lib/td/command/options.rb in td-0.11.11.2 vs lib/td/command/options.rb in td-0.11.12
- old
+ new
@@ -26,16 +26,10 @@
s = File.expand_path(s)
end
opts[:output] = s
opts[:format] ||= 'tsv'
}
- op.on('-f', '--format FORMAT', 'format of the result to write to the file (tsv, csv, json, msgpack, and msgpack.gz)') {|s|
- unless ['tsv', 'csv', 'json', 'msgpack', 'msgpack.gz'].include?(s)
- raise "Unknown format #{s.dump}. Supported formats are: tsv, csv, json, msgpack, and msgpack.gz"
- end
- opts[:format] = s
- }
op.on('-l', '--limit ROWS', 'limit the number of result rows shown when not outputting to file') {|s|
unless s.to_i > 0
raise "Invalid limit number. Must be a positive integer"
end
opts[:limit] = s.to_i
@@ -50,12 +44,24 @@
op.on('--null STRING', "null expression in csv or tsv") {|s|
opts[:render_opts][:null_expr] = s.to_s
}
+ write_format_option(op) {|s| opts[:format] = s }
+
# CAUTION: this opts is filled by op.cmd_parse
opts
end
+ def write_format_option(op)
+ op.on('-f', '--format FORMAT', 'format of the result to write to the file (tsv, csv, json, msgpack, and msgpack.gz)') {|s|
+ unless ['tsv', 'csv', 'json', 'msgpack', 'msgpack.gz'].include?(s)
+ raise "Unknown format #{s.dump}. Supported formats are: tsv, csv, json, msgpack, and msgpack.gz"
+ end
+
+ yield(s)
+ }
+ end
+ module_function :write_format_option
end # module Options
end # module Command
end # module TreasureData