Sha256: acea5b3538bd3935f629bb962b11132a3e813c4569bdfda16f941fb027cbe33c

Contents?: true

Size: 1021 Bytes

Versions: 4

Compression:

Stored size: 1021 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.recognised_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

4 entries across 4 versions & 1 rubygems

Version Path
clamp-0.2.3 lib/clamp/subcommand/execution.rb
clamp-0.2.2 lib/clamp/subcommand/execution.rb
clamp-0.2.1 lib/clamp/subcommand/execution.rb
clamp-0.2.0 lib/clamp/subcommand/execution.rb