public/Write-CmdletParameter.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110

function Write-CmdletParameter() {
    Param(
        [Parameter(Position = 0)]
        [PsCustomObject] $Model,

        [Parameter(Position = 1)]
        [String] $Template
    )


    $test = $Model.Parameters.Parameter;
    $parameters = $Model.Parameters;
   
    if($test -and $test.Length) {
        $out = "";
        if([String]::IsNullOrWhitespace($HeaderTemplate)) {
            $HeaderTemplate = "`n## Parameters`n`n"
        }


        $out += $HeaderTemplate;

        $parameters.Parameter | ForEach-Object {
            $description = $_.Description;
            if($description.Text) {
                $description = $description.Text;
                if($description -is [Array]) {
                    $description = [String]::Join("`n", $description)
                }
                
            }
            
            $name = (Write-EscapedMarkdownString $_.Name)
            $type = $_.type.name;
            $position = $_.Position
            $globbing = $_.Globbing
            $aliases = (Write-EscapedMarkdownString $_.Aliases)
            $description = (Write-EscapedMarkdownString $description)
            $required = (Write-EscapedMarkdownString $_.Required)
            $input = (Write-EscapedMarkdownString $_.PipelineInput)
            $default = (Write-EscapedMarkdownString $_.DefaultValue)
            
            if([string]::IsNullOrWhitespace($description)) {
                $description = " "
            }

            if([string]::IsNullOrWhitespace($input)) {
                $input = " "
            }

            if([string]::IsNullOrWhitespace($aliases)) {
                $aliases = " "
            }

            if([string]::IsNullOrWhitespace($default)) {
                $default = " "
            }

            $out += @"
 
### \-$name
 
$description
 
<table>
   <tbody>
        <tr>
            <td>Type:</td>
            <td>$type</td>
        </tr>
        <tr>
            <td>Aliases:</td>
            <td>$aliases</td>
        </tr>
        <tr>
            <td>Required:</td>
            <td>$required</td>
        </tr>
        <tr>
            <td>Position:</td>
            <td>$position</td>
        </tr>
        <tr>
            <td>Default:</td>
            <td>$default</td>
        </tr>
        <tr>
            <td>Accept Pipeline Input:</td>
            <td>$input</td>
        </tr>
        <tr>
            <td>Accept Wildcard Characters:</td>
            <td>$globbing</td>
        </tr>
   </tbody>
</table>
 
 
"@

        }

        

        return $out;
    }


    return "";
}