Improved parser error messages.

This commit is contained in:
kojix2 2020-08-14 11:45:47 +09:00
parent 1f713d2a7b
commit 3c6a4b46b1

View File

@ -71,24 +71,41 @@ module Uplot
parsers.default = nil parsers.default = nil
main_parser.banner = <<~MSG main_parser.banner = <<~MSG
Program: Uplot (Tools for plotting on the terminal) Program: uplot (Tools for plotting on the terminal)
Version: #{Uplot::VERSION} (using unicode_plot #{UnicodePlot::VERSION}) Version: #{Uplot::VERSION} (using unicode_plot #{UnicodePlot::VERSION})
Usage: uplot <command> [options] Usage: uplot <command> [options]
Command: #{parsers.keys.join(' ')} Command: #{parsers.keys.join(' ')}
Options:
MSG MSG
begin
main_parser.order!(argv) main_parser.order!(argv)
rescue OptionParser::ParseError => e
warn "uplot: #{e.message}"
exit 1
end
@ptype = argv.shift @ptype = argv.shift
unless parsers.has_key?(@ptype) unless parsers.has_key?(@ptype)
puts main_parser.help if @ptype.nil?
warn "unrecognized command '#{@ptype}'" warn main_parser.help
else
warn "uplot: unrecognized command '#{@ptype}'"
end
exit 1 exit 1
end end
parser = parsers[@ptype] parser = parsers[@ptype]
begin
parser.parse!(argv) unless argv.empty? parser.parse!(argv) unless argv.empty?
rescue OptionParser::ParseError => e
warn "uplot: #{e.message}"
exit 1
end
end end
def run def run