11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
# File 'lib/duyoji_todo/command/options.rb', line 11
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 => e
abort "OptionParserMissingArgument : #{e.message}"
rescue OptionParser::InvalidOption => e
abort "OptionParserInvalidOption : #{e.message}"
rescue ArgumentError => e
abort "ArgumentError : #{e.message}"
end
options
end
|