mirror of
https://github.com/red-data-tools/YouPlot.git
synced 2025-05-06 15:11:12 +08:00
Allows you to specify the output file
This commit is contained in:
parent
3aceae9279
commit
ccfbaa7bde
@ -25,6 +25,7 @@ module Uplot
|
|||||||
delimiter = parser.delimiter
|
delimiter = parser.delimiter
|
||||||
transpose = parser.transpose
|
transpose = parser.transpose
|
||||||
headers = parser.headers
|
headers = parser.headers
|
||||||
|
pass = parser.pass
|
||||||
output = parser.output
|
output = parser.output
|
||||||
count = parser.count
|
count = parser.count
|
||||||
fmt = parser.fmt
|
fmt = parser.fmt
|
||||||
@ -41,7 +42,7 @@ module Uplot
|
|||||||
@raw_inputs << input
|
@raw_inputs << input
|
||||||
@data = Preprocessing.input(input, delimiter, headers, transpose)
|
@data = Preprocessing.input(input, delimiter, headers, transpose)
|
||||||
pp @data if @debug
|
pp @data if @debug
|
||||||
case command
|
plot = case command
|
||||||
when :bar, :barplot
|
when :bar, :barplot
|
||||||
Plot.barplot(data, params, @count)
|
Plot.barplot(data, params, @count)
|
||||||
when :count, :c
|
when :count, :c
|
||||||
@ -60,9 +61,23 @@ module Uplot
|
|||||||
Plot.boxplot(data, params)
|
Plot.boxplot(data, params)
|
||||||
else
|
else
|
||||||
raise "unrecognized plot_type: #{command}"
|
raise "unrecognized plot_type: #{command}"
|
||||||
end.render($stderr)
|
end
|
||||||
|
|
||||||
print input if output
|
if output.is_a?(IO)
|
||||||
|
plot.render(output)
|
||||||
|
else
|
||||||
|
File.open(output, 'w') do |f|
|
||||||
|
plot.render(f)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if pass.is_a?(IO)
|
||||||
|
print input
|
||||||
|
elsif pass
|
||||||
|
File.open(pass, 'w') do |f|
|
||||||
|
f.print(input)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -7,7 +7,7 @@ module Uplot
|
|||||||
class Command
|
class Command
|
||||||
class Parser
|
class Parser
|
||||||
attr_reader :command, :params,
|
attr_reader :command, :params,
|
||||||
:delimiter, :transpose, :headers, :output, :count, :fmt, :debug
|
:delimiter, :transpose, :headers, :pass, :output, :count, :fmt, :debug
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@command = nil
|
@command = nil
|
||||||
@ -16,7 +16,8 @@ module Uplot
|
|||||||
@delimiter = "\t"
|
@delimiter = "\t"
|
||||||
@transpose = false
|
@transpose = false
|
||||||
@headers = nil
|
@headers = nil
|
||||||
@output = false
|
@pass = false
|
||||||
|
@output = $stderr
|
||||||
@count = false
|
@count = false
|
||||||
@fmt = 'xyy'
|
@fmt = 'xyy'
|
||||||
@debug = false
|
@debug = false
|
||||||
@ -26,7 +27,10 @@ module Uplot
|
|||||||
OptionParser.new do |opt|
|
OptionParser.new do |opt|
|
||||||
opt.program_name = 'uplot'
|
opt.program_name = 'uplot'
|
||||||
opt.version = Uplot::VERSION
|
opt.version = Uplot::VERSION
|
||||||
opt.on('-O', 'outputs the standard input data to the standard output', TrueClass) do |v|
|
opt.on('-O', '--pass [VAL]', 'file to output standard input data to [stdout]') do |v|
|
||||||
|
@pass = v || $stdout
|
||||||
|
end
|
||||||
|
opt.on('-o', '--output VAL', 'file to output results to [stderr]') do |v|
|
||||||
@output = v
|
@output = v
|
||||||
end
|
end
|
||||||
opt.on('-d', '--delimiter VAL', 'use DELIM instead of TAB for field delimiter', String) do |v|
|
opt.on('-d', '--delimiter VAL', 'use DELIM instead of TAB for field delimiter', String) do |v|
|
||||||
|
Loading…
Reference in New Issue
Block a user