72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
|
# File 'lib/flapjack/patches.rb', line 72
def parse!(parsing_result,argument_handling_strategy)
parsed_command_options = {}
command = parsing_result.command
arguments = nil
loop do
command._action.call if command.passthrough
option_parser_factory = OptionParserFactory.for_command(command,@accepts)
option_block_parser = CommandOptionBlockParser.new(option_parser_factory, self.error_handler)
option_block_parser.command = command
arguments = parsing_result.arguments
arguments = option_block_parser.parse!(arguments)
parsed_command_options[command] = option_parser_factory.options_hash_with_defaults_set!
command_finder = CommandFinder.new(command.commands,command.get_default_command)
next_command_name = arguments.shift
gli_major_version, gli_minor_version = GLI::VERSION.split('.')
required_options = [command.flags, parsing_result.command, parsed_command_options[command]]
verify_required_options!(*required_options)
begin
command = command_finder.find_command(next_command_name)
rescue AmbiguousCommand
arguments.unshift(next_command_name)
break
rescue UnknownCommand
arguments.unshift(next_command_name)
unless command.get_default_command.nil?
command = command_finder.find_command(command.get_default_command)
end
break
end
end
parsed_command_options[command] ||= {}
command_options = parsed_command_options[command]
this_command = command.parent
child_command_options = command_options
while this_command.kind_of?(command.class)
this_command_options = parsed_command_options[this_command] || {}
child_command_options[GLI::Command::PARENT] = this_command_options
this_command = this_command.parent
child_command_options = this_command_options
end
parsing_result.command_options = command_options
parsing_result.command = command
parsing_result.arguments = Array(arguments.compact)
verify_arguments!(parsing_result.arguments, parsing_result.command) if argument_handling_strategy == :strict
parsing_result
end
|