Sha256: 547a554ce58a285f4807512acdf3d64de3fcef83ae5563c9a631359d9f618844

Contents?: true

Size: 1.64 KB

Versions: 31

Compression:

Stored size: 1.64 KB

Contents

module Docman
  class ExecuteScriptCmd < Docman::Command

    register_command :script


    def validate_command
      raise Docman::CommandValidationError.new("Please provide 'execution_dir' param") if self['execution_dir'].nil?
      raise Docman::CommandValidationError.new("Please provide 'location' param") if self['location'].nil?
      raise Docman::CommandValidationError.new("Please provide 'context'") if @context.nil?
      raise Docman::CommandValidationError.new("Context should be of type 'Info'") unless @context.is_a? Docman::Info
      replace_placeholder(self['execution_dir'])
      replace_placeholder(self['location'])
      raise Docman::CommandValidationError.new("Directory #{self['execution_dir']} not exists") unless File.directory? self['execution_dir']
      raise Docman::CommandValidationError.new("Script #{self['location']} not exists") unless File.file? self['location']
    end

    def execute
      Dir.chdir self['execution_dir']
      logger.info "Script execution: #{self['location']}"
      params = self['params'].nil? ? '' : prepare_params(self['params'])

      # Fix for ^M issue when saved from GitLab or windows.
      `cat #{self['location']} | tr -d '\r' > #{self['location']}-tmp`
      `rm -f #{self['location']}`
      `mv #{self['location']}-tmp #{self['location']}`
      `chmod a+x #{self['location']}`
      logger.info `#{self['location']} #{params}`
      $?.exitstatus
    end

    def prepare_params(params)
      result = []
      params.each do |param|
        case param
          when 'environment'
            result << @context.environment_name
        end
      end
      result.join(' ')
    end

  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
docman-0.0.76 lib/docman/commands/execute_script_cmd.rb
docman-0.0.75 lib/docman/commands/execute_script_cmd.rb
docman-0.0.74 lib/docman/commands/execute_script_cmd.rb
docman-0.0.73 lib/docman/commands/execute_script_cmd.rb
docman-0.0.72 lib/docman/commands/execute_script_cmd.rb
docman-0.0.71 lib/docman/commands/execute_script_cmd.rb
docman-0.0.70 lib/docman/commands/execute_script_cmd.rb
docman-0.0.69 lib/docman/commands/execute_script_cmd.rb
docman-0.0.68 lib/docman/commands/execute_script_cmd.rb
docman-0.0.67 lib/docman/commands/execute_script_cmd.rb
docman-0.0.66 lib/docman/commands/execute_script_cmd.rb
docman-0.0.65 lib/docman/commands/execute_script_cmd.rb
docman-0.0.64 lib/docman/commands/execute_script_cmd.rb
docman-0.0.63 lib/docman/commands/execute_script_cmd.rb
docman-0.0.62 lib/docman/commands/execute_script_cmd.rb
docman-0.0.61 lib/docman/commands/execute_script_cmd.rb
docman-0.0.60 lib/docman/commands/execute_script_cmd.rb
docman-0.0.59 lib/docman/commands/execute_script_cmd.rb
docman-0.0.58 lib/docman/commands/execute_script_cmd.rb
docman-0.0.57 lib/docman/commands/execute_script_cmd.rb