7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
# File 'lib/mdg/command/options.rb', line 7
def self.parse!(argv)
options = {}
sub_command_parsers = create_sub_command_parsers(options)
command_parser = create_command_parser
begin
command_parser.order!(argv)
options[:command] = argv.shift
sub_command_parsers[options[:command]].parse! argv
if %w(update delete).include?(options[:command])
raise ArgumentError, "#{options[:command]} id not found." if argv.empty?
options[:id] = Integer(argv.first)
end
rescue OptionParser::MissingArgument, OptionParser::InvalidOption, ArgumentError => e
abort e.message
end
options
end
|