diff --git a/lib/uplot/command.rb b/lib/uplot/command.rb index 58c5aeb..8f82e6b 100644 --- a/lib/uplot/command.rb +++ b/lib/uplot/command.rb @@ -105,8 +105,7 @@ module Uplot end end - def parse_options(argv = ARGV) - main_parser = create_default_parser + def create_sub_parser parsers = Hash.new { |h, k| h[k] = create_default_parser } parsers[:barplot] = \ @@ -200,6 +199,12 @@ module Uplot # Preventing the generation of new sub-commands parsers.default = nil + parsers + end + + def parse_options(argv = ARGV) + main_parser = create_default_parser + sub_parsers = create_sub_parser # Usage and help messages main_parser.banner = \ @@ -209,7 +214,7 @@ module Uplot Usage: uplot [options] - Command: #{parsers.keys.join(' ')} + Command: #{sub_parsers.keys.join(' ')} Options: MSG @@ -223,7 +228,7 @@ module Uplot @command = argv.shift&.to_sym - unless parsers.has_key?(command) + unless sub_parsers.has_key?(command) if command.nil? warn main_parser.help else @@ -231,7 +236,7 @@ module Uplot end exit 1 end - parser = parsers[command] + parser = sub_parsers[command] begin parser.parse!(argv) unless argv.empty?