Skip to content

Commit

Permalink
Changes as requested by @hbuckle
Browse files Browse the repository at this point in the history
1. Parameterised the install_options method to make testing easier.

2. Added an example in the documentation of how to pass a hash and a switch to the install_options argument
  • Loading branch information
palintir committed Jan 27, 2019
1 parent d097248 commit 998e819
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,19 @@ file{"C:\Program Files\PackageManagement\ProviderAssemblies\nuget\2.8.5.208\Micr

`puppet-powershellmodule` implements a [package type](http://docs.puppet.com/references/latest/type.html#package) with a resource provider, which is built into Puppet.

The implementation supports the [install_options](https://puppet.com/docs/puppet/6.2/type.html#package-attribute-install_options) attribute which can be used to pass additional options to the PowerShell Install-Modules command, e.g.:

```
package { 'xPSDesiredStateConfiguration':
ensure => latest,
provider => 'windowspowershell',
source => 'PSGallery',
install_options => [ '-AllowClobber',
{ '-proxy' => 'http://proxy.local.domain' } ]
}
```

### pspackageprovider

#### Properties/Parameters
Expand Down
10 changes: 5 additions & 5 deletions lib/puppet/provider/package/powershellcore.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ def update
# @param options [Array]
# @return Concatenated list of options
# @api private
def install_options
return unless @resource[:install_options]
def install_options(options)
return unless options

@resource[:install_options].collect do |val|
options.collect do |val|
case val
when Hash
val.keys.sort.collect do |k|
Expand Down Expand Up @@ -88,7 +88,7 @@ def install_command
command = "Install-Module #{@resource[:name]} -Scope AllUsers -Force"
command << " -RequiredVersion #{@resource[:ensure]}" unless [:present, :latest].include? @resource[:ensure]
command << " -Repository #{@resource[:source]}" if @resource[:source]
command << " #{install_options}" if @resource[:install_options]
command << " #{install_options(@resource[:install_options])}" if @resource[:install_options]
command
end

Expand All @@ -103,7 +103,7 @@ def latest_command
def update_command
command = "Install-Module #{@resource[:name]} -Scope AllUsers -Force"
command << " -Repository #{@resource[:source]}" if @resource[:source]
command << " #{install_options}" if @resource[:install_options]
command << " #{install_options(@resource[:install_options])}" if @resource[:install_options]
command
end
end

0 comments on commit 998e819

Please sign in to comment.