Sha256: 99752a45680f5668b8255d756e4061677e5b15e80e610680682f424a119e2783

Contents?: true

Size: 996 Bytes

Versions: 1

Compression:

Stored size: 996 Bytes

Contents

require 'optparse'

#require 'lemon'
#require 'yaml'

module Lemon

  # Lemon Command-line tool base class.
  class Command

    # Used to map command-line options to command classes.
    # This must be overridden in subclasses, and return an
    # array of of options, e.g. [ '-g', '--generate'].
    def self.options
      raise "not implemented"
    end

    # Stores a list of command classes.
    def self.commands
      @commands ||= []
    end

    # When this class is inherited, it is registered to the commands list.
    def self.inherited(command_class)
      commands << command_class
    end

    # Factory method to initialize and run choosen sub-command.
    def self.run
      cmd = commands.find do |command_class|
        [command_class.options].flatten.find do |opt|
          ARGV.delete(opt)
        end
      end
      cmd ? cmd.run : Commands::Test.run
    end

  end

end

require 'lemon/commands/test'
require 'lemon/commands/coverage'
require 'lemon/commands/generate'

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
lemon-0.6 lib/lemon/command.rb