mirror of
https://github.com/red-data-tools/YouPlot.git
synced 2025-05-06 07:10:10 +08:00
Add create_sub_parser method
This commit is contained in:
parent
b1df2ed544
commit
50cb8d7463
@ -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 <command> [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?
|
||||
|
Loading…
Reference in New Issue
Block a user