Method: Specinfra::Backend::PowerShell::ScriptHelper#create_script

Defined in:
lib/specinfra/backend/powershell/script_helper.rb

#create_script(command) ⇒ Object

[View source]

49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/specinfra/backend/powershell/script_helper.rb', line 49

def create_script command
  if command.is_a? Command
    ps_functions = command.import_functions.map { |f| File.read(File.join(File.dirname(__FILE__), 'support', f)) }
    script = build_command(command.script)
    script = add_pre_command(script)
    <<-EOF
$exitCode = 1
$ProgressPreference = "SilentlyContinue"
try {
  #{ps_functions.join("\n")}
  $success = (#{script})
  if ($success -is [Boolean] -and $success) { $exitCode = 0 }
} catch {
  Write-Output $_.Exception.Message
}
Write-Output "Exiting with code: $exitCode"
exit $exitCode
  EOF
  else
    script = build_command(command.to_s)
    add_pre_command(script)
  end
end