Class: Train::Extras::PowerShellCommand
- Inherits:
-
CommandWrapperBase
- Object
- CommandWrapperBase
- Train::Extras::PowerShellCommand
- 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
-
#initialize(backend, options) ⇒ PowerShellCommand
constructor
A new instance of PowerShellCommand.
- #run(script) ⇒ Object
-
#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.
- #to_s ⇒ Object
Methods inherited from CommandWrapperBase
Constructor Details
#initialize(backend, options) ⇒ PowerShellCommand
Returns a new instance of PowerShellCommand.
107 108 109 110 |
# File 'lib/train/extras/command_wrapper.rb', line 107 def initialize(backend, ) @backend = backend () end |
Instance Method Details
#run(script) ⇒ Object
112 113 114 115 116 117 118 |
# File 'lib/train/extras/command_wrapper.rb', line 112 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
122 123 124 |
# File 'lib/train/extras/command_wrapper.rb', line 122 def safe_script(script) "$ProgressPreference='SilentlyContinue';" + script end |
#to_s ⇒ Object
126 127 128 |
# File 'lib/train/extras/command_wrapper.rb', line 126 def to_s 'PowerShell CommandWrapper' end |