Sha256: 3a9e8a202cb087496bb0da708aa64664b0f42f3f70995547cce347aa4930ea82

Contents?: true

Size: 720 Bytes

Versions: 1

Compression:

Stored size: 720 Bytes

Contents

module Clamp

  class Subcommand < Struct.new(:name, :description, :subcommand_class)

    def help
      [name, description]
    end

  end

  module SubcommandSupport

    def recognised_subcommands
      @recognised_subcommands ||= []
    end

    def subcommand(name, description, subcommand_class = self, &block)
      if block
        # generate a anonymous sub-class
        subcommand_class = Class.new(subcommand_class, &block)
      end
      recognised_subcommands << Subcommand.new(name, description, subcommand_class)
    end

    def has_subcommands?
      !recognised_subcommands.empty?
    end

    def find_subcommand(name)
      recognised_subcommands.find { |sc| sc.name == name }
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
clamp-0.0.7 lib/clamp/subcommand_support.rb