internal/functions/Get-TypeParameterContent.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
45
46
47
48
49
50
51
52
Function Get-TypeParameterContent {
  <#
  .SYNOPSIS
    Return the text for a Puppet Resource API Type attribute given a DSC resource's ParameterInfo
  .DESCRIPTION
    Return the text for a Puppet Resource API Type Attribute (a property or parameter), given a DSC
    Resouce's parameter information. It will return the text but _not_ directly write out the file.
  .PARAMETER ParameterInfo
    A PSCustomObject with the required parameter information added to a DSC resource via the
    Get-DscResourceTypeInformation function.
  .EXAMPLE
    Get-TypeParameterContent (Get-DscResourceTypeInformation -Name PSRepository).ParameterInfo
 
    This will retrieve a DSC resource from the PSModulePath, retrieve the information
    needed to represent the DSC resource's properties as Puppet Resource API type
    attributes and then return the representation of that DSC resource appropriate
    for the Puppet Resource API.
  #>

  [cmdletbinding()]
  Param (
    [OutputType([String], [String[]])]
    [pscustomobject]$ParameterInfo
  )

  ForEach ($Parameter in $ParameterInfo) {
    New-Object -TypeName System.String @"
    dsc_$($Parameter.name): {
      type: $($Parameter.Type -split "`n" -join "`n "),
$(
  If ([string]::IsNullOrEmpty($Parameter.Help)) {
    " desc: %q{},"
  } Else {
    # Assemble the Description String with appropriate indentation
    $DescStrings = @(' desc: %q{')
    $Parameter.Help.Split("`n") | ForEach-Object -Process {$DescStrings += " $_"}
    $DescStrings += ' },'
    $DescStrings -Join "`n"
  }
)
$(
  If ($Parameter.is_namevar -eq 'true'){
    " behaviour: :namevar,"
  }
)
      mandatory_for_get: $($Parameter.mandatory_for_get),
      mandatory_for_set: $($Parameter.mandatory_for_set),
      mof_type: '$($Parameter.mof_type)',
      mof_is_embedded: $($Parameter.mof_is_embedded),
    },
"@

  }
}