lib/rcoli/model.rb in rcoli-0.5.3 vs lib/rcoli/model.rb in rcoli-0.5.4

- old
+ new

@@ -59,20 +59,28 @@ raise InvalidCommand, "#'{arg}' is not a valid option" end else if (cmd = find_command(arg)) result.command = cmd + cmd.put_default_values(result) cmd.parse_args(args, result) elsif (commands.empty?) result.arguments << arg else raise InvalidCommand, "'#{arg}' is not a valid #{@name} command" end end parse_args(args, result) end + def put_default_values(result) + options.find_all{|option| option.respond_to? :value_of_default_value and option.value_of_default_value}.each do |option| + target = self.parent ? :options : :global_options + option.keys.each{|key| result.send(target)[key] = option.value_of_default_value} + end + end + def find_command(name) commands.find{|command| command.value_of_name.eql? name} end private @@ -171,9 +179,10 @@ include Help include CommandContainer def execute(args, context) result = ParsedArgs.new + put_default_values(result) parse_args(args, result) if result.command action = result.command.get_action raise "Invalid configuration. Missing action block." unless action context.instance_exec(result.global_options, result.options, result.arguments, &@pre_action) if (@pre_action and !result.command.solitaire?) \ No newline at end of file