Sha256: 574bd403e1e54d7375615ec094da9e712cfbf375d87ef93d736a988306c81710

Contents?: true

Size: 790 Bytes

Versions: 1

Compression:

Stored size: 790 Bytes

Contents

module Clamp
  class Subcommand

    module Execution

      protected
      
      def execute_subcommand
        signal_usage_error "no subcommand specified" if arguments.empty?
        subcommand_name = arguments.shift
        subcommand_class = find_subcommand_class(subcommand_name)
        subcommand = subcommand_class.new("#{invocation_path} #{subcommand_name}", context)
        subcommand.parent_command = self
        subcommand.run(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

1 entries across 1 versions & 1 rubygems

Version Path
clamp-0.1.0 lib/clamp/subcommand/execution.rb