Class: Train::Extras::PowerShellCommand

Inherits:
CommandWrapperBase show all
Defined in:
lib/train/extras/command_wrapper.rb

Overview

this is required if you run locally on windows, winrm connections provide a PowerShell shell automatically TODO: only activate in local mode

Instance Method Summary collapse

Methods inherited from CommandWrapperBase

#verify

Constructor Details

#initialize(backend, options) ⇒ PowerShellCommand

Returns a new instance of PowerShellCommand.



104
105
106
107
# File 'lib/train/extras/command_wrapper.rb', line 104

def initialize(backend, options)
  @backend = backend
  validate_options(options)
end

Instance Method Details

#run(script) ⇒ Object



109
110
111
112
113
114
115
# File 'lib/train/extras/command_wrapper.rb', line 109

def run(script)
  # wrap the script to ensure we always run it via powershell
  # especially in local mode, we cannot be sure that we get a Powershell
  # we may just get a `cmd`.
  # TODO: we may want to opt for powershell.exe -command instead of `encodeCommand`
  "powershell -encodedCommand #{WinRM::PowershellScript.new(safe_script(script)).encoded}"
end

#safe_script(script) ⇒ Object

reused from github.com/WinRb/WinRM/blob/master/lib/winrm/command_executor.rb suppress the progress stream from leaking to stderr



119
120
121
# File 'lib/train/extras/command_wrapper.rb', line 119

def safe_script(script)
  "$ProgressPreference='SilentlyContinue';" + script
end

#to_sObject



123
124
125
# File 'lib/train/extras/command_wrapper.rb', line 123

def to_s
  'PowerShell CommandWrapper'
end