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.
105 106 107 108 |
# File 'lib/train/extras/command_wrapper.rb', line 105 def initialize(backend, ) @backend = backend () end |
Instance Method Details
#run(script) ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/train/extras/command_wrapper.rb', line 110 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
120 121 122 |
# File 'lib/train/extras/command_wrapper.rb', line 120 def safe_script(script) "$ProgressPreference='SilentlyContinue';" + script end |
#to_s ⇒ Object
124 125 126 |
# File 'lib/train/extras/command_wrapper.rb', line 124 def to_s 'PowerShell CommandWrapper' end |