module Clamp::Subcommand::Execution
Support for subcommand execution.
This module is mixed into command instances that have subcommands, overriding default behaviour in {Clamp::Command}.
Public Instance Methods
Source
# File lib/clamp/subcommand/execution.rb, line 15 def execute # delegate to subcommand subcommand = instantiate_subcommand(subcommand_name) subcommand.run(subcommand_arguments) end
override default Command
behaviour
Private Instance Methods
Source
# File lib/clamp/subcommand/execution.rb, line 38 def find_subcommand_class(name) subcommand_def = self.class.find_subcommand(name) return subcommand_def.subcommand_class if subcommand_def subcommand_missing(name) end
Source
# File lib/clamp/subcommand/execution.rb, line 23 def instantiate_subcommand(name) subcommand_class = find_subcommand_class(name) subcommand = subcommand_class.new(invocation_path_for(name), context) self.class.inheritable_attributes.each do |attribute| next unless attribute.of(self).defined? attribute.of(subcommand).set(attribute.of(self).get) end subcommand end
Source
# File lib/clamp/subcommand/execution.rb, line 33 def invocation_path_for(name) param_names = self.class.parameters.select(&:inheritable?).map(&:name) [invocation_path, *param_names, name].join(" ") end
Source
# File lib/clamp/subcommand/execution.rb, line 44 def verify_required_options_are_set # not required end