3
3
4
4
Puppet ::Type . type ( :package ) . provide :powershellcore , parent : Puppet ::Provider ::Package do
5
5
initvars
6
- has_feature :installable , :uninstallable , :upgradeable , :versionable
6
+ has_feature :installable , :uninstallable , :upgradeable , :versionable , :install_options
7
7
commands pwsh : 'pwsh'
8
8
9
9
def self . invoke_ps_command ( command )
@@ -44,6 +44,32 @@ def update
44
44
self . class . invoke_ps_command update_command
45
45
end
46
46
47
+ # Turns a array of install_options into flags to be passed to a command.
48
+ # The options can be passed as a string or hash. Note that passing a hash
49
+ # should only be used in case "-foo bar" must be passed,
50
+ # Regular flags like '-foobar' must be passed as a string.
51
+ # which can be accomplished with:
52
+ # install_options => [ '-foobar',{ '-foo' => 'bar' } ]
53
+ # This will result in the following being passed as arguments to the command:
54
+ # -foobar -foo bar
55
+ # @param options [Array]
56
+ # @return Concatenated list of options
57
+ # @api private
58
+ def install_options
59
+ return unless @resource [ :install_options ]
60
+
61
+ @resource [ :install_options ] . collect do |val |
62
+ case val
63
+ when Hash
64
+ val . keys . sort . collect do |k |
65
+ "#{ k } #{ val [ k ] } "
66
+ end
67
+ else
68
+ val
69
+ end
70
+ end . flatten . join ( " " )
71
+ end
72
+
47
73
def self . instances_command
48
74
# Get-Package is way faster than Get-InstalledModule
49
75
<<-COMMAND
@@ -62,6 +88,7 @@ def install_command
62
88
command = "Install-Module #{ @resource [ :name ] } -Scope AllUsers -Force"
63
89
command << " -RequiredVersion #{ @resource [ :ensure ] } " unless [ :present , :latest ] . include? @resource [ :ensure ]
64
90
command << " -Repository #{ @resource [ :source ] } " if @resource [ :source ]
91
+ command << " #{ install_options } " if @resource [ :install_options ]
65
92
command
66
93
end
67
94
@@ -76,6 +103,7 @@ def latest_command
76
103
def update_command
77
104
command = "Install-Module #{ @resource [ :name ] } -Scope AllUsers -Force"
78
105
command << " -Repository #{ @resource [ :source ] } " if @resource [ :source ]
106
+ command << " #{ install_options } " if @resource [ :install_options ]
79
107
command
80
108
end
81
109
end
0 commit comments