Sha256: fb07cbe1c0f5fa4234be3103cf78bacebc7fe585bc51a426e0da8d13eca02d39

Contents?: true

Size: 1.33 KB

Versions: 1

Compression:

Stored size: 1.33 KB

Contents

#require File.dirname(File.dirname(__FILE__)) + '/roll.rb'
require 'roll'

module Roll

  # = Command-line Interface
  #--
  # TODO: clean command to remove dead directories from environment
  #++
  class Command

    # Command-line arguments.
    attr :args

    # Command-line options.
    attr :opts

    # Instance of OptionParser.
    attr :op

    # Initialize and execute command.
    def self.main(*argv)
      #cmd   = argv.shift
      idx = argv.index{ |e| e !~ /^\-/ }
      cmd = idx ? argv.delete_at(idx) : 'help'
      begin
        require "roll/commands/#{cmd}"
      rescue LoadError
        cmd = 'help'
        require "roll/commands/#{cmd}"
      end
      klass = ::Roll.const_get("Command#{cmd.capitalize}")
      klass.new(*argv).execute
    end

    # New Command.
    def initialize(*argv)
      # only need optparse when command is run
      require 'optparse'
      @op   = OptionParser.new
      @args = argv
      @opts = {}
    end

    #
    def execute
      setup

      op.on_tail("--warn", "-w", "Show warnings.") do
        $VERBOSE = true
      end

      op.on_tail("--debug", "Run in debugging mode.") do
        $DEBUG   = true
        $VERBOSE = true
      end

      op.on_tail("--help", "-h", "Display this help message.") do
        puts op
        exit
      end

      op.parse!(args)

      call
    end

  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
roll-1.2.0 lib/roll/command.rb