Sha256: 94dd160a86a665ae8f8b25926e022c6ba503f8cee76f1ad9f83bcf2b411714d6

Contents?: true

Size: 1019 Bytes

Versions: 2

Compression:

Stored size: 1019 Bytes

Contents

module Clamp
  class Subcommand

    module Execution

      protected
      
      def execute_subcommand
        signal_usage_error "no subcommand specified" unless subcommand_name
        subcommand_class = find_subcommand_class(subcommand_name)
        subcommand = subcommand_class.new("#{invocation_path} #{subcommand_name}", context)
        self.class.declared_options.each do |option|
          option_set = instance_variable_defined?(option.ivar_name)
          if option_set && subcommand.respond_to?(option.write_method)
            subcommand.send(option.write_method, self.send(option.read_method))
          end
        end
        subcommand.run(subcommand_arguments)
      end

      private

      def find_subcommand(name)
        self.class.find_subcommand(name) || 
        signal_usage_error("No such sub-command '#{name}'")
      end

      def find_subcommand_class(name)
        subcommand = find_subcommand(name)
        subcommand.subcommand_class if subcommand
      end

    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
clamp-0.1.8 lib/clamp/subcommand/execution.rb
clamp-0.1.7 lib/clamp/subcommand/execution.rb