Class: Beaker::SedCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/beaker/command.rb

Instance Attribute Summary

Attributes inherited from Command

#args, #command, #environment, #options

Instance Method Summary collapse

Methods inherited from Command

#args_string, #cmd_line, #options_string

Constructor Details

#initialize(platform, expression, filename, opts = {}) ⇒ Object

sets up a SedCommand for a particular platform

the purpose is to abstract away platform-dependent details of the sed command

Options Hash (opts):

  • :temp_file (String)

    The temp file to use for in-place substitution (only applies to solaris hosts, they don't provide the -i option)



166
167
168
169
170
171
172
173
174
175
176
# File 'lib/beaker/command.rb', line 166

def initialize platform, expression, filename, opts = {}
  command = "sed -i -e \"#{expression}\" #{filename}"
  if platform =~ /solaris|aix|osx|openbsd/
    command.slice! '-i '
    temp_file = opts[:temp_file] ? opts[:temp_file] : "#{filename}.tmp"
    command << " > #{temp_file} && mv #{temp_file} #{filename} && rm -f #{temp_file}"
  end
  args = []
  opts['ENV'] ||= Hash.new
  super( command, args, opts )
end