Sha256: 55d69297d8146f44cc32e5a014b8dd09f252329c0ae21d6a226db20a743aba22

Contents?: true

Size: 1.12 KB

Versions: 4

Compression:

Stored size: 1.12 KB

Contents

require 'albacore/support/attrmethods'

module Albacore
  module RunCommand
    extend AttrMethods
    
    attr_accessor :command, :working_directory
    attr_array :parameters
    
    def initialize
      @working_directory = Dir.pwd
      @parameters = []
      super()
    end
    
    def run_command(name="Command Line", parameters=nil)
      begin
        params = Array.new
        params << parameters unless parameters.nil?
        params << @parameters unless (@parameters.nil? || @parameters.length==0)
        
        cmd = get_command(params)
        @logger.debug "Executing #{name}: #{cmd}"
        
        Dir.chdir(@working_directory) do
          return system(cmd)
        end

      rescue Exception => e
        puts "Error While Running Command Line Tool: #{e}"
        raise
      end
    end

    def get_command(params)
      executable = @command
      unless command.nil?
        executable = File.expand_path(@command) if File.exists?(@command)
      end
      cmd = "\"#{executable}\""
      cmd +=" #{params.join(' ')}" if params.length > 0
      cmd
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
albacore-0.2.5 lib/albacore/support/runcommand.rb
albacore-0.2.4 lib/albacore/support/runcommand.rb
albacore-0.2.3 lib/albacore/support/runcommand.rb
albacore-0.2.2 lib/albacore/support/runcommand.rb