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

Parameters:

  • platform (String)

    The host platform string

  • expression (String)

    The sed expression

  • filename (String)

    The file to apply the sed expression to

  • opts (Hash{Symbol=>String}) (defaults to: {})

    Additional options

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)



163
164
165
166
167
168
169
170
171
172
173
# File 'lib/beaker/command.rb', line 163

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