internal/functions/Update-PuppetModuleFixture.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function Update-PuppetModuleFixture {
  <#
    .SYNOPSIS
      Update the Puppet module's .fixtures.yml
    .DESCRIPTION
      Update the Puppet module's .fixtures.yml with dependencies.
    .PARAMETER PuppetModuleFolderPath
      The Path, relative or literal, to the Puppet module's root folder.
    .PARAMETER Confirm
      Prompts for confirmation before overwriting the file
    .PARAMETER WhatIf
      Shows what would happen if the function runs.
    .EXAMPLE
      Update-PuppetModuleFixture -PuppetModuleFolderPath ./import/powershellget
      This command will update `./import/powershellget/.fixtures.yml`, adding a
      key to the Forge Modules fixture for puppetlabs/pwshlib.
  #>

  [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')]
  param (
    [string]$PuppetModuleFolderPath
  )

  begin {}

  process {
    Try {
      $ErrorActionPreference = 'Stop'
      $FixturesFilePath = Resolve-Path -Path (Join-Path $PuppetModuleFolderPath ".fixtures.yml")
      $FixturesYaml = Get-Content -Path $FixturesFilePath -Raw | ConvertFrom-Yaml
      $FixturesYaml.fixtures.forge_modules = @{
        pwshlib = 'puppetlabs/pwshlib'
      }
    } Catch {
      # Rethrow any exceptions from the above commands
      $PSCmdlet.ThrowTerminatingError($PSItem)
    }
    $YamlOutput = "---`n" + (ConvertTo-Yaml -Data $FixturesYaml)
    If ($PSCmdlet.ShouldProcess($FixturesFilePath, "Overwrite YAML with:`n`n$YamlOutput")) {
      Out-Utf8File -Path $FixturesFilePath -InputObject $YamlOutput
    }
  }

  end {}
}