Add create_main_parser method

This commit is contained in:
kojix2 2020-09-15 19:57:37 +09:00
parent 3e3b1cdfec
commit 40c5d9fbdf

View File

@ -7,7 +7,7 @@ module Uplot
class Command class Command
attr_accessor :params, :command attr_accessor :params, :command
attr_reader :raw_inputs, :data, :fmt attr_reader :main_parser, :sub_parsers, :raw_inputs, :data, :fmt
def initialize def initialize
@params = Params.new @params = Params.new
@ -76,6 +76,7 @@ module Uplot
.on('--debug', TrueClass) do |v| .on('--debug', TrueClass) do |v|
@debug = v @debug = v
end end
yield opt if block_given?
end end
end end
@ -176,10 +177,8 @@ module Uplot
parsers parsers
end end
def parse_options(argv = ARGV) def create_main_parser
main_parser = create_default_parser create_default_parser do |main_parser|
sub_parsers = create_sub_parsers
# Usage and help messages # Usage and help messages
main_parser.banner = \ main_parser.banner = \
<<~MSG <<~MSG
@ -192,6 +191,12 @@ module Uplot
Options: Options:
MSG MSG
end
end
def parse_options(argv = ARGV)
@sub_parsers = create_sub_parsers
@main_parser = create_main_parser
begin begin
main_parser.order!(argv) main_parser.order!(argv)