Add helper option for setting custom module path on PowerShell executes

This commit is contained in:
Chris Roberts 2018-06-12 10:44:12 -07:00
parent 4efec92643
commit 5325000fa6
1 changed files with 18 additions and 6 deletions

View File

@ -54,8 +54,12 @@ module Vagrant
if opts.delete(:sudo) || opts.delete(:runas) if opts.delete(:sudo) || opts.delete(:runas)
powerup_command(path, args, opts) powerup_command(path, args, opts)
else else
env = opts.delete(:env) if mpath = opts.delete(:module_path)
if env m_env = opts.fetch(:env, {})
m_env["PSModulePath"] = "$env:PSModulePath+';#{mpath}'"
opts[:env] = m_env
end
if env = opts.delete(:env)
env = env.map{|k,v| "$env:#{k}=#{v}"}.join(";") + "; " env = env.map{|k,v| "$env:#{k}=#{v}"}.join(";") + "; "
end end
command = [ command = [
@ -85,8 +89,12 @@ module Vagrant
# Returns stdout string if exit code is zero. # Returns stdout string if exit code is zero.
def self.execute_cmd(command, **opts) def self.execute_cmd(command, **opts)
validate_install! validate_install!
env = opts.delete(:env) if mpath = opts.delete(:module_path)
if env m_env = opts.fetch(:env, {})
m_env["PSModulePath"] = "$env:PSModulePath+';#{mpath}'"
opts[:env] = m_env
end
if env = opts.delete(:env)
env = env.map{|k,v| "$env:#{k}=#{v}"}.join(";") + "; " env = env.map{|k,v| "$env:#{k}=#{v}"}.join(";") + "; "
end end
c = [ c = [
@ -112,8 +120,12 @@ module Vagrant
# @param [Block] block Ruby block # @param [Block] block Ruby block
def self.execute_inline(*command, **opts, &block) def self.execute_inline(*command, **opts, &block)
validate_install! validate_install!
env = opts.delete(:env) if mpath = opts.delete(:module_path)
if env m_env = opts.fetch(:env, {})
m_env["PSModulePath"] = "$env:PSModulePath+';#{mpath}'"
opts[:env] = m_env
end
if env = opts.delete(:env)
env = env.map{|k,v| "$env:#{k}=#{v}"}.join(";") + "; " env = env.map{|k,v| "$env:#{k}=#{v}"}.join(";") + "; "
end end
c = [ c = [