mirror of
https://github.com/red-data-tools/YouPlot.git
synced 2025-06-24 01:41:13 +08:00
Do not exit when using as a library
This commit is contained in:
parent
62cc6ba364
commit
8db1306e07
@ -3,4 +3,4 @@
|
|||||||
|
|
||||||
require 'youplot'
|
require 'youplot'
|
||||||
|
|
||||||
YouPlot::Command.new.run
|
YouPlot::Command.new.run_as_executable
|
||||||
|
@ -3,4 +3,4 @@
|
|||||||
|
|
||||||
require 'youplot'
|
require 'youplot'
|
||||||
|
|
||||||
YouPlot::Command.new.run
|
YouPlot::Command.new.run_as_executable
|
||||||
|
@ -6,4 +6,10 @@ require 'youplot/dsv'
|
|||||||
require 'youplot/command'
|
require 'youplot/command'
|
||||||
|
|
||||||
module YouPlot
|
module YouPlot
|
||||||
|
class << self
|
||||||
|
attr_accessor :run_as_executable
|
||||||
|
def run_as_executable?
|
||||||
|
@run_as_executable
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -181,14 +181,14 @@ module YouPlot
|
|||||||
warn " Headers: \e[35m#{data.headers.inspect}\e[0m"
|
warn " Headers: \e[35m#{data.headers.inspect}\e[0m"
|
||||||
warn " The first item is: \e[35m\"#{series[0][0]}\"\e[0m"
|
warn " The first item is: \e[35m\"#{series[0][0]}\"\e[0m"
|
||||||
warn " The last item is : \e[35m\"#{series[0][-1]}\"\e[0m"
|
warn " The last item is : \e[35m\"#{series[0][-1]}\"\e[0m"
|
||||||
exit 1
|
exit 1 if YouPlot.run_as_executable?
|
||||||
end
|
end
|
||||||
if fmt == 'xyxy' && series.size.odd?
|
if fmt == 'xyxy' && series.size.odd?
|
||||||
warn 'YouPlot: In the xyxy format, the number of series must be even.'
|
warn 'YouPlot: In the xyxy format, the number of series must be even.'
|
||||||
warn ''
|
warn ''
|
||||||
warn " Number of series: \e[35m#{series.size}\e[0m"
|
warn " Number of series: \e[35m#{series.size}\e[0m"
|
||||||
warn " Headers: \e[35m#{data.headers.inspect}\e[0m"
|
warn " Headers: \e[35m#{data.headers.inspect}\e[0m"
|
||||||
exit 1
|
exit 1 if YouPlot.run_as_executable?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -22,6 +22,11 @@ module YouPlot
|
|||||||
@backend = YouPlot::Backends::UnicodePlotBackend
|
@backend = YouPlot::Backends::UnicodePlotBackend
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def run_as_executable
|
||||||
|
YouPlot.run_as_executable = true
|
||||||
|
run
|
||||||
|
end
|
||||||
|
|
||||||
def run
|
def run
|
||||||
parser.parse_options(@argv)
|
parser.parse_options(@argv)
|
||||||
@command ||= parser.command
|
@command ||= parser.command
|
||||||
|
@ -93,7 +93,7 @@ module YouPlot
|
|||||||
# This is why you need the code below.
|
# This is why you need the code below.
|
||||||
parser.on('--help', 'print sub-command help menu') do
|
parser.on('--help', 'print sub-command help menu') do
|
||||||
puts parser.help
|
puts parser.help
|
||||||
exit
|
exit if YouPlot.run_as_executable?
|
||||||
end
|
end
|
||||||
parser.on('--debug', TrueClass, 'print preprocessed data') do |v|
|
parser.on('--debug', TrueClass, 'print preprocessed data') do |v|
|
||||||
options[:debug] = v
|
options[:debug] = v
|
||||||
@ -136,7 +136,7 @@ module YouPlot
|
|||||||
main_parser.on('--help', 'print sub-command help menu') do
|
main_parser.on('--help', 'print sub-command help menu') do
|
||||||
puts main_parser.banner
|
puts main_parser.banner
|
||||||
puts
|
puts
|
||||||
exit
|
exit if YouPlot.run_as_executable?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -25,10 +25,10 @@ module YouPlot
|
|||||||
Data.new(headers, series)
|
Data.new(headers, series)
|
||||||
elsif h_size > s_size
|
elsif h_size > s_size
|
||||||
warn "\e[35mThe number of headers is greater than the number of series.\e[0m"
|
warn "\e[35mThe number of headers is greater than the number of series.\e[0m"
|
||||||
exit 1
|
exit 1 if YouPlot.run_as_executable?
|
||||||
elsif h_size < s_size
|
elsif h_size < s_size
|
||||||
warn "\e[35mThe number of headers is less than the number of series.\e[0m"
|
warn "\e[35mThe number of headers is less than the number of series.\e[0m"
|
||||||
exit 1
|
exit 1 if YouPlot.run_as_executable?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user