1
1
require 'puppet/provider/package'
2
+ require 'json'
2
3
3
4
Puppet ::Type . type ( :package ) . provide :psmodule , parent : Puppet ::Provider ::Package do
4
5
confine operatingsystem : :windows
@@ -25,12 +26,8 @@ def self.invoke_ps_command(command)
25
26
26
27
def self . instances
27
28
result = invoke_ps_command instances_command
28
- result . each_slice ( 2 ) . collect do |mod |
29
- new (
30
- name : mod [ 0 ] . strip ,
31
- ensure : mod [ 1 ] . strip . split ( ',' ) ,
32
- provider : 'psmodule'
33
- )
29
+ result . each . collect do |line |
30
+ new ( JSON . parse ( line . strip , symbolize_names : true ) )
34
31
end
35
32
end
36
33
@@ -61,17 +58,20 @@ def self.instances_command
61
58
# Get-Package is way faster than Get-InstalledModule
62
59
<<-COMMAND
63
60
Get-Package -AllVersions -ProviderName PowerShellGet -Scope AllUsers -Type Module |
64
- Group-Object -Property Name | % {
65
- $_.Name
66
- ($_.Group).Version -join ','
61
+ Group-Object -Property Name | % {
62
+ [ordered]@{
63
+ 'name' = $_.Name
64
+ 'ensure' = @(($_.Group).Version)
65
+ 'provider' = 'psmodule'
66
+ } | ConvertTo-Json -Depth 99 -Compress
67
67
}
68
68
COMMAND
69
69
end
70
70
71
71
def install_command
72
72
command = "Install-Module #{ @resource [ :name ] } -Force"
73
73
command << " -RequiredVersion #{ @resource [ :ensure ] } " unless [ :present , :latest ] . include? @resource [ :ensure ]
74
- command << " -Source #{ @resource [ :source ] } " if @resource [ :source ]
74
+ command << " -Repository #{ @resource [ :source ] } " if @resource [ :source ]
75
75
command
76
76
end
77
77
@@ -85,7 +85,7 @@ def latest_command
85
85
86
86
def update_command
87
87
command = "Install-Module #{ @resource [ :name ] } -Force"
88
- command << " -Source #{ @resource [ :source ] } " if @resource [ :source ]
88
+ command << " -Repository #{ @resource [ :source ] } " if @resource [ :source ]
89
89
command
90
90
end
91
91
end
0 commit comments