forked from chocolatey/choco
-
Notifications
You must be signed in to change notification settings - Fork 2
/
GenerateDocs.ps1
574 lines (461 loc) · 32.4 KB
/
GenerateDocs.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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
# Copyright © 2017 Chocolatey Software, Inc
# Copyright © 2011 - 2017 RealDimensions Software, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
#
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Special thanks to Glenn Sarti (https://github.com/glennsarti) for his help on this.
$ErrorActionPreference = 'Stop'
$thisDirectory = (Split-Path -parent $MyInvocation.MyCommand.Definition);
$psModuleName = 'chocolateyInstaller'
$psModuleLocation = [System.IO.Path]::GetFullPath("$thisDirectory\src\chocolatey.resources\helpers\chocolateyInstaller.psm1")
$docsFolder = [System.IO.Path]::GetFullPath("$thisDirectory\docs\generated")
$chocoExe = [System.IO.Path]::GetFullPath("$thisDirectory\code_drop\chocolatey\console\choco.exe")
$lineFeed = "`r`n"
$sourceLocation = 'https://github.com/chocolatey/choco/blob/stable/'
$sourceCommands = $sourceLocation + 'src/chocolatey/infrastructure.app/commands'
$sourceFunctions = $sourceLocation + 'src/chocolatey.resources/helpers/functions'
$global:powerShellReferenceTOC = @'
---
Order: 40
xref: powershell-reference
Title: PowerShell Reference
Description: PowerShell Functions aka Helpers Reference
RedirectFrom:
- docs/helpers-reference
- docs/HelpersReference
---
# PowerShell Functions aka Helpers Reference
<!-- This documentation file is automatically generated from the files at $sourceFunctions using $($sourceLocation)GenerateDocs.ps1. Contributions are welcome at the original location(s). -->
## Summary
In your Chocolatey packaging, you have the ability to use these functions (and others with Chocolatey's [PowerShell Extensions](xref:extensions)) to work with all aspects of software management. Keep in mind Chocolatey's automation scripts are just PowerShell, so you can do manage anything you want.
> :memo: **NOTE** These scripts are for package scripts, not for use directly in PowerShell. This is in the create packages section, not the using Chocolatey section.
## Main Functions
These functions call other functions and many times may be the only thing you need in your [chocolateyInstall.ps1 file](xref:chocolatey-install-ps1).
* [Install-ChocolateyPackage](xref:install-chocolateypackage)
* [Install-ChocolateyZipPackage](xref:install-chocolateyzippackage)
* [Install-ChocolateyPowershellCommand](xref:install-chocolateypowershellcommand)
* [Install-ChocolateyVsixPackage](xref:install-chocolateyvsixpackage)
## Error / Success Functions
* [Write-ChocolateySuccess](xref:write-chocolateysuccess) - **DEPRECATED**
* [Write-ChocolateyFailure](xref:write-chocolateyfailure) - **DEPRECATED**
You really don't need a try catch with Chocolatey PowerShell files anymore.
## More Functions
### Administrative Access Functions
When creating packages that need to run one of the following commands below, one should add the tag `admin` to the nuspec.
* [Install-ChocolateyPackage](xref:install-chocolateypackage)
* [Start-ChocolateyProcessAsAdmin](xref:start-chocolateyprocessasadmin)
* [Install-ChocolateyInstallPackage](xref:install-chocolateyinstallpackage)
* [Install-ChocolateyPath](xref:install-chocolateypath) - when specifying machine path
* [Install-ChocolateyEnvironmentVariable](xref:install-chocolateyenvironmentvariable) - when specifying machine path
* [Install-ChocolateyExplorerMenuItem](xref:install-chocolateyexplorermenuitem)
* [Install-ChocolateyFileAssociation](xref:install-chocolateyfileassociation)
### Non-Administrator Safe Functions
When you have a need to run Chocolatey without Administrative access required (non-default install location), you can run the following functions without administrative access.
These are the functions from above as one list.
* [Install-ChocolateyZipPackage](xref:install-chocolateyzippackage)
* [Install-ChocolateyPowershellCommand](xref:install-chocolateypowershellcommand)
* [Write-ChocolateySuccess](xref:write-chocolateysuccess)
* [Write-ChocolateyFailure](xref:write-chocolateyfailure)
* [Get-ChocolateyWebFile](xref:get-chocolateywebfile)
* [Get-ChocolateyUnzip](xref:get-chocolateyunzip)
* [Install-ChocolateyPath](xref:install-chocolateypath) - when specifying user path
* [Install-ChocolateyEnvironmentVariable](xref:install-chocolateyenvironmentvariable) - when specifying user path
* [Install-ChocolateyDesktopLink](xref:install-chocolateydesktoplink) - **DEPRECATED** - see [Install-ChocolateyShortcut](xref:install-chocolateyshortcut)
* [Install-ChocolateyPinnedTaskBarItem](xref:install-chocolateypinnedtaskbaritem)
* [Install-ChocolateyShortcut](xref:install-chocolateyshortcut) - v0.9.9+
* [Update-SessionEnvironment](xref:update-sessionenvironment)
* [Get-PackageParameters](xref:get-packageparameters) - v0.10.8+
## Complete List (alphabetical order)
'@
function Get-Aliases($commandName){
$aliasOutput = ''
Get-Alias -Definition $commandName -ErrorAction SilentlyContinue | %{ $aliasOutput += "``$($_.Name)``$lineFeed"}
if ($aliasOutput -eq $null -or $aliasOutput -eq '') {
$aliasOutput = 'None'
}
Write-Output $aliasOutput
}
function Convert-Example($objItem) {
@"
**$($objItem.title.Replace('-','').Trim())**
~~~powershell
$($objItem.Code.Replace("`n",$lineFeed))
$($objItem.remarks | ? { $_.Text -ne ''} | % { Write-Output $_.Text.Replace("`n", $lineFeed) })
~~~
"@
}
function Replace-CommonItems($text) {
if ($text -eq $null) {return $text}
$text = $text.Replace("`n",$lineFeed)
$text = $text -replace "\*\*NOTE:\*\*", "> :memo: **NOTE**"
$text = $text -replace '(community feed[s]?[^\]]|community repository)', '[$1](https://community.chocolatey.org/packages)'
$text = $text -replace '(Chocolatey for Business|Chocolatey Professional|Chocolatey Pro)(?=[^\w])', '[$1](https://chocolatey.org/compare)'
$text = $text -replace '(Pro[fessional]\s?/\s?Business)', '[$1](https://chocolatey.org/compare)'
$text = $text -replace '([Ll]icensed editions)', '[$1](https://chocolatey.org/compare)'
$text = $text -replace '([Ll]icensed versions)', '[$1](https://chocolatey.org/compare)'
$text = $text -replace '\(https://docs.chocolatey.org/en-us/create/automatic-packages\)', '(xref:automatic-packaging)'
$text = $text -replace 'Learn more about using this at https://docs.chocolatey.org/en-us/guides/create/parse-packageparameters-argument', '[Learn more](xref:parse-package-parameters)'
$text = $text -replace 'at https://docs.chocolatey.org/en-us/guides/create/parse-packageparameters-argument#step-3---use-core-community-extension', 'in [the docs](xref:parse-package-parameters#step-3-use-core-community-extension)'
$text = $text -replace 'https://docs.chocolatey.org/en-us/guides/create/parse-packageparameters-argument', 'https://docs.chocolatey.org/en-us/guides/create/parse-packageparameters-argument'
$text = $text -replace '\[community feed\)\]\(https://community.chocolatey.org/packages\)', '[community feed](https://community.chocolatey.org/packages))'
Write-Output $text
}
function Convert-Syntax($objItem, $hasCmdletBinding) {
$cmd = $objItem.Name
if ($objItem.parameter -ne $null) {
$objItem.parameter | % {
$cmd += ' `' + $lineFeed
$cmd += " "
if ($_.required -eq $false) { $cmd += '['}
$cmd += "-$($_.name.substring(0,1).toupper() + $_.name.substring(1))"
if ($_.parameterValue -ne $null) { $cmd += " <$($_.parameterValue)>" }
if ($_.parameterValueGroup -ne $null) { $cmd += " {" + ($_.parameterValueGroup.parameterValue -join ' | ') + "}"}
if ($_.required -eq $false) { $cmd += ']'}
}
}
if ($hasCmdletBinding) { $cmd += " [<CommonParameters>]"}
Write-Output "$lineFeed~~~powershell$lineFeed$($cmd)$lineFeed~~~"
}
function Convert-Parameter($objItem, $commandName) {
$parmText = $lineFeed + "### -$($objItem.name.substring(0,1).ToUpper() + $objItem.name.substring(1))"
if ( ($objItem.parameterValue -ne $null) -and ($objItem.parameterValue -ne 'SwitchParameter') ) {
$parmText += ' '
if ([string]($objItem.required) -eq 'false') { $parmText += "["}
$parmText += "<$($objItem.parameterValue)>"
if ([string]($objItem.required) -eq 'false') { $parmText += "]"}
}
$parmText += $lineFeed
if ($objItem.description -ne $null) {
$parmText += (($objItem.description | % { Replace-CommonItems $_.Text }) -join "$lineFeed") + $lineFeed + $lineFeed
}
if ($objItem.parameterValueGroup -ne $null) {
$parmText += "$($lineFeed)Valid options: " + ($objItem.parameterValueGroup.parameterValue -join ", ") + $lineFeed + $lineFeed
}
$aliases = [string]((Get-Command -Name $commandName).parameters."$($objItem.Name)".Aliases -join ', ')
$required = [string]($objItem.required)
$position = [string]($objItem.position)
$defValue = [string]($objItem.defaultValue)
$acceptPipeline = [string]($objItem.pipelineInput)
$padding = ($aliases.Length, $required.Length, $position.Length, $defValue.Length, $acceptPipeline.Length | Measure-Object -Maximum).Maximum
$parmText += @"
Property | Value
---------------------- | $([string]('-' * $padding))
Aliases | $($aliases)
Required? | $($required)
Position? | $($position)
Default Value | $($defValue)
Accept Pipeline Input? | $($acceptPipeline)
"@
Write-Output $parmText
}
function Convert-CommandText {
param(
[string]$commandText,
[string]$commandName = ''
)
if ( $commandText -match '^\s?NOTE: Options and switches apply to all items passed, so if you are\s?$' `
-or $commandText -match '^\s?installing multiple packages, and you use \`\-\-version\=1\.0\.0\`, it is\s?$' `
-or $commandText -match '^\s?going to look for and try to install version 1\.0\.0 of every package\s?$' `
-or $commandText -match '^\s?passed\. So please split out multiple package calls when wanting to\s?$' `
-or $commandText -match '^\s?pass specific options\.\s?$' `
) {
return
}
$commandText = $commandText -creplace '^(.+)(\s+Command\s*)$', "# `$1`$2 (choco $commandName)"
$commandText = $commandText -creplace '^(Usage|Troubleshooting|Examples|Exit Codes|Connecting to Chocolatey.org|See It In Action|Alternative Sources|Resources|Packages.config|Scripting \/ Integration - Best Practices \/ Style Guide)', '## $1'
$commandText = $commandText -replace '^(Commands|How To Pass Options)', '## $1'
$commandText = $commandText -replace '^(WebPI|Windows Features|Ruby|Cygwin|Python)\s*$', '### $1'
$commandText = $commandText -replace 'NOTE\:', '> :memo: **NOTE**'
$commandText = $commandText -replace '\*> :memo: \*\*NOTE\*\*\*', '> :memo: **NOTE**'
$commandText = $commandText -replace 'the command reference', '[how to pass arguments](xref:choco-commands#how-to-pass-options-switches)'
$commandText = $commandText -replace '(community feed[s]?|community repository)', '[$1](https://comminty.chocolatey.org/packages)'
#$commandText = $commandText -replace '\`(apikey|install|upgrade|uninstall|list|search|info|outdated|pin)\`', '[[`$1`|Commands$1]]'
$commandText = $commandText -replace '\`([choco\s]*)(apikey|install|upgrade|uninstall|list|search|info|outdated|pin)\`', '[`$1$2`](xref:choco-command-$2)'
$commandText = $commandText -replace '^(.+):\s(.+.gif)$', '![$1]($2)'
$commandText = $commandText -replace '^(\s+)\<\?xml', "~~~xml$lineFeed`$1<?xml"
$commandText = $commandText -replace '^(\s+)</packages>', "`$1</packages>$lineFeed~~~"
$commandText = $commandText -replace '(Chocolatey for Business|Chocolatey Professional|Chocolatey Pro)(?=[^\w])', '[$1](https://chocolatey.org/compare)'
$commandText = $commandText -replace '(Pro[fessional]\s?/\s?Business)', '[$1](https://chocolatey.org/compare)'
$commandText = $commandText -replace '([Ll]icensed editions)', '[$1](https://chocolatey.org/compare)'
$commandText = $commandText -replace '([Ll]icensed versions)', '[$1](https://chocolatey.org/compare)'
$commandText = $commandText -replace 'https://raw.githubusercontent.com/wiki/chocolatey/choco/images', '/assets/images'
$commandText = $commandText -replace 'https://chocolatey.org/docs/features-automatically-recompile-packages', 'https://docs.chocolatey.org/en-us/guides/create/recompile-packages'
$commandText = $commandText -replace 'https://chocolatey.org/docs/features-private-cdn', 'https://docs.chocolatey.org/en-us/features/private-cdn'
$commandText = $commandText -replace 'https://chocolatey.org/docs/features-virus-check', 'https://docs.chocolatey.org/en-us/features/virus-check'
$commandText = $commandText -replace 'https://chocolatey.org/docs/features-synchronize', 'https://docs.chocolatey.org/en-us/features/package-synchronization'
$commandText = $commandText -replace 'explicity', 'explicit'
$commandText = $commandText -replace 'https://chocolatey.org/docs/features-create-packages-from-installers', 'https://docs.chocolatey.org/en-us/features/package-builder'
$commandText = $commandText -replace 'See https://chocolatey.org/docs/features-create-packages-from-installers', 'See more information about [Package Builder features](xref:package-builder)'
$commandText = $commandText -replace 'See https://docs.chocolatey.org/en-us/features/package-builder', 'See more information about [Package Builder features](xref:package-builder)'
$commandText = $commandText -replace 'https://chocolatey.org/docs/features-install-directory-override', 'https://docs.chocolatey.org/en-us/features/install-directory-override'
$commandText = $commandText -replace 'y.org/docs/features-package-reducer', 'y.org/docs/en-us/features/package-reducer'
$commandText = $commandText -replace 'https://chocolatey.org/docs/features-package-reducer', 'https://docs.chocolatey.org/en-us/features/package-reducer'
$commandText = $commandText -replace 'https://chocolatey.org/docs/en-us/features/package-reducer', 'https://docs.chocolatey.org/en-us/features/package-reducer'
$commandText = $commandText -replace '\[community feed\)\]\(https://community.chocolatey.org/packages\)', '[community feed](https://community.chocolatey.org/packages))'
$optionsSwitches = @'
## $1
> :memo: **NOTE** Options and switches apply to all items passed, so if you are
running a command like install that allows installing multiple
packages, and you use `--version=1.0.0`, it is going to look for and
try to install version 1.0.0 of every package passed. So please split
out multiple package calls when wanting to pass specific options.
Includes [default options/switches](xref:choco-commands#default-options-and-switches) (included below for completeness).
~~~
'@
$commandText = $commandText -replace '^(Options and Switches)', $optionsSwitches
$optionsSwitches = @'
## $1
> :memo: **NOTE** Options and switches apply to all items passed, so if you are
running a command like install that allows installing multiple
packages, and you use `--version=1.0.0`, it is going to look for and
try to install version 1.0.0 of every package passed. So please split
out multiple package calls when wanting to pass specific options.
~~~
'@
$commandText = $commandText -replace '^(Default Options and Switches)', $optionsSwitches
Write-Output $commandText
}
function Convert-CommandReferenceSpecific($commandText) {
$commandText = [Regex]::Replace($commandText, '\s?\s?\*\s(\w+)\s\-',
{
param($m)
$commandName = $m.Groups[1].Value
$commandNameUpper = $($commandName.Substring(0,1).ToUpper() + $commandName.Substring(1))
" * [$commandName](xref:choco-command-$($commandName)) -"
}
)
#$commandText = $commandText -replace '\s?\s?\*\s(\w+)\s\-', ' * [[$1|Commands$1]] -'
$commandText = $commandText.Replace("## Default Options and Switches", "## See Help Menu In Action$lineFeed$lineFeed![choco help in action](/assets/images/gifs/choco_help.gif)$lineFeed$lineFeed## Default Options and Switches")
Write-Output $commandText
}
function Generate-TopLevelCommandReference {
Write-Host "Generating Top Level Command Reference"
$fileName = "$docsFolder\choco\commands\index.md"
$commandOutput = @("---")
$commandOutput += @("Order: 40")
$commandOutput += @("xref: choco-commands")
$commandOutput += @("Title: Commands")
$commandOutput += @("Description: Full list of all available Chocolatey commands")
$commandOutput += @("RedirectFrom:")
$commandOutput += @(" - docs/commandsreference")
$commandOutput += @(" - docs/commands-reference")
$commandOutput += @("---$lineFeed")
$commandOutput += @("# Command Reference$lineFeed")
$commandOutput += @("<!-- This file is automatically generated based on output from the files at $sourceCommands using $($sourceLocation)GenerateDocs.ps1. Contributions are welcome at the original location(s). --> $lineFeed")
$commandOutput += $(& $chocoExe -? -r)
$commandOutput += @("$lineFeed~~~$lineFeed")
$commandOutput += @("$lineFeed$lineFeed*NOTE:* This documentation has been automatically generated from ``choco -h``. $lineFeed")
$commandOutput | %{ Convert-CommandText($_) } | %{ Convert-CommandReferenceSpecific($_) } | Out-File $fileName -Encoding UTF8 -Force
}
function Move-GeneratedFiles {
if(-not(Test-Path "$docsFolder\create\commands")){ mkdir "$docsFolder\create\commands" -EA Continue | Out-Null }
Move-Item -Path "$docsFolder\choco\commands\apikey.md" -Destination "$docsFolder\create\commands\api-key.md"
Move-Item -Path "$docsFolder\choco\commands\new.md" -Destination "$docsFolder\create\commands\new.md"
Move-Item -Path "$docsFolder\choco\commands\pack.md" -Destination "$docsFolder\create\commands\pack.md"
Move-Item -Path "$docsFolder\choco\commands\push.md" -Destination "$docsFolder\create\commands\push.md"
}
function Generate-CommandReference($commandName, $order) {
if(-not(Test-Path "$docsFolder\choco\commands")){ mkdir "$docsFolder\choco\commands" -EA Continue | Out-Null }
$fileName = Join-Path "$docsFolder\choco\commands" "$($commandName.ToLower()).md"
$commandNameLower = $commandName.ToLower()
Write-Host "Generating $fileName ..."
$commandOutput += @("---")
$commandOutput += @("Order: $order")
$commandOutput += @("xref: choco-command-$commandNameLower")
if($commandName -eq 'List') {
$commandOutput += @("Title: $commandName/Search")
$commandOutput += @("Description: $commandName/Search Command (choco $commandNameLower)")
} else {
$commandOutput += @("Title: $commandName")
$commandOutput += @("Description: $commandName Command (choco $commandNameLower)")
}
$commandOutput += @("RedirectFrom:")
$commandOutput += @(" - docs/commands$commandNameLower")
$commandOutput += @(" - docs/commands-$commandNameLower")
if($commandName -eq 'Features') {
$commandOutput += @("ShowInNavbar: false")
$commandOutput += @("ShowInSidebar: false")
}
$commandOutput += @("---$lineFeed")
$commandOutput += @("<!-- This file is automatically generated based on output from $($sourceCommands)/Chocolatey$($commandName)Command.cs using $($sourceLocation)GenerateDocs.ps1. Contributions are welcome at the original location(s). If the file is not found, it is not part of the open source edition of Chocolatey or the name of the file is different. --> $lineFeed")
$commandOutput += $(& $chocoExe $commandName.ToLower() -h -r)
$commandOutput += @("$lineFeed~~~$lineFeed$lineFeed[Command Reference](xref:choco-commands)")
$commandOutput += @("$lineFeed$lineFeed*NOTE:* This documentation has been automatically generated from ``choco $($commandName.ToLower()) -h``. $lineFeed")
$commandOutput | %{ Convert-CommandText $_ $commandName.ToLower() } | Out-File $fileName -Encoding UTF8 -Force
}
try
{
Write-Host "Importing the Module $psModuleName ..."
Import-Module "$psModuleLocation" -Force -Verbose
# Switch Get-PackageParameters back for documentation
Remove-Item alias:Get-PackageParameters
Remove-Item function:Get-PackageParametersBuiltIn
Set-Alias -Name Get-PackageParametersBuiltIn -Value Get-PackageParameters -Scope Global
if (Test-Path($docsFolder)) { Remove-Item $docsFolder -Force -Recurse -EA SilentlyContinue }
if(-not(Test-Path $docsFolder)){ mkdir $docsFolder -EA Continue | Out-Null }
if(-not(Test-Path "$docsFolder\create\functions")){ mkdir "$docsFolder\create\functions" -EA Continue | Out-Null }
Write-Host 'Creating per PowerShell function markdown files...'
$helperOrder = 10;
Get-Command -Module $psModuleName -CommandType Function | ForEach-Object -Process { Get-Help $_ -Full } | ForEach-Object -Process { `
$commandName = $_.Name
$fileName = Join-Path "$docsFolder\create\functions" "$($_.Name.ToLower()).md"
$global:powerShellReferenceTOC += "$lineFeed * [$commandName](xref:$([System.IO.Path]::GetFileNameWithoutExtension($fileName)))"
$hasCmdletBinding = (Get-Command -Name $commandName).CmdLetBinding
Write-Host "Generating $fileName ..."
$SplitName = $_.Name -split "-"
$NameNoHyphen = $_.Name -replace '-', ''
if($_.Name -eq 'Get-OSArchitectureWidth') {
$FormattedName = "get-os-architecture-width"
} elseif($_.Name -eq 'Get-UACEnabled') {
$FormattedName = "get-uac-enabled"
}else {
$FormattedName = $SplitName[0].ToLower() + ($SplitName[1] -creplace '[A-Z]', '-$&').ToLower()
}
@"
---
Order: $($helperOrder)
xref: $($_.Name.ToLower())
Title: $($_.Name)
Description: Information on $($_.Name) function
RedirectFrom:
- docs/helpers-$($FormattedName)
- docs/helpers$($NameNoHyphen.ToLower())
---
# $($_.Name)
<!-- This documentation is automatically generated from $sourceFunctions/$($_.Name)`.ps1 using $($sourceLocation)GenerateDocs.ps1. Contributions are welcome at the original location(s). -->
$(Replace-CommonItems $_.Synopsis)
## Syntax
$( ($_.syntax.syntaxItem | % { Convert-Syntax $_ $hasCmdletBinding }) -join "$lineFeed$lineFeed")
$( if ($_.description -ne $null) { $lineFeed + "## Description" + $lineFeed + $lineFeed + $(Replace-CommonItems $_.description.Text) })
$( if ($_.alertSet -ne $null) { $lineFeed + "## Notes" + $lineFeed + $lineFeed + $(Replace-CommonItems $_.alertSet.alert.Text) })
## Aliases
$(Get-Aliases $_.Name)
$( if ($_.Examples -ne $null) { Write-Output "$lineFeed## Examples$lineFeed$lineFeed"; ($_.Examples.Example | % { Convert-Example $_ }) -join "$lineFeed$lineFeed"; Write-Output "$lineFeed" })
## Inputs
$( if ($_.InputTypes -ne $null -and $_.InputTypes.Length -gt 0 -and -not $_.InputTypes.Contains('inputType')) { $lineFeed + " * $($_.InputTypes)" + $lineFeed} else { 'None'})
## Outputs
$( if ($_.ReturnValues -ne $null -and $_.ReturnValues.Length -gt 0 -and -not $_.ReturnValues.StartsWith('returnValue')) { "$lineFeed * $($_.ReturnValues)$lineFeed"} else { 'None'})
## Parameters
$( if ($_.parameters.parameter.count -gt 0) { $_.parameters.parameter | % { Convert-Parameter $_ $commandName }}) $( if ($hasCmdletBinding) { "$lineFeed### <CommonParameters>$lineFeed$($lineFeed)This cmdlet supports the common parameters: -Verbose, -Debug, -ErrorAction, -ErrorVariable, -OutBuffer, and -OutVariable. For more information, see ``about_CommonParameters`` http://go.microsoft.com/fwlink/p/?LinkID=113216 ." } )
$( if ($_.relatedLinks -ne $null) {Write-Output "$lineFeed## Links$lineFeed$lineFeed"; $_.relatedLinks.navigationLink | ? { $_.linkText -ne $null} | % { Write-Output "* [$($_.LinkText)](xref:$($_.LinkText.ToLower()))$lineFeed" }})
[Function Reference](xref:powershell-reference)
> :memo: **NOTE** This documentation has been automatically generated from ``Import-Module `"`$env:ChocolateyInstall\helpers\chocolateyInstaller.psm1`" -Force; Get-Help $($_.Name) -Full``.
View the source for [$($_.Name)]($sourceFunctions/$($_.Name)`.ps1)
"@ | Out-File $fileName -Encoding UTF8 -Force
$helperOrder = $helperOrder + 10
}
Write-Host "Generating Top Level PowerShell Reference"
$fileName = Join-Path "$docsFolder\create\functions" 'index.md'
$global:powerShellReferenceTOC += @'
## Chocolatey for Business Functions
* [Install-ChocolateyWindowsService](xref:install-chocolateywindowsservice)
* [Start-ChocolateyWindowsService](xref:start-chocolateywindowsservice)
* [Stop-ChocolateyWindowsService](xref:stop-chocolateywindowsservice)
* [Uninstall-ChocolateyWindowsService](xref:uninstall-chocolateywindowsservice)
## Variables
There are also a number of environment variables providing access to some values from the nuspec and other information that may be useful. They are accessed via `$env:variableName`.
### Environment Variables
Chocolatey makes a number of environment variables available (You can access any of these with $env:TheVariableNameBelow):
* TEMP/TMP - Overridden to the CacheLocation, but may be the same as the original TEMP folder
* ChocolateyInstall - Top level folder where Chocolatey is installed
* ChocolateyPackageName - The name of the package, equivalent to the `<id />` field in the nuspec (0.9.9+)
* ChocolateyPackageTitle - The title of the package, equivalent to the `<title />` field in the nuspec (0.10.1+)
* ChocolateyPackageVersion - The version of the package, equivalent to the `<version />` field in the nuspec (0.9.9+)
* ChocolateyPackageFolder - The top level location of the package folder - the folder where Chocolatey has downloaded and extracted the NuGet package, typically `C:\ProgramData\chocolatey\lib\packageName`.
#### Advanced Environment Variables
The following are more advanced settings:
* ChocolateyPackageParameters - Parameters to use with packaging, not the same as install arguments (which are passed directly to the native installer). Based on `--package-parameters`. (0.9.8.22+)
* CHOCOLATEY_VERSION - The version of Choco you normally see. Use if you are 'lighting' things up based on choco version. (0.9.9+) - Otherwise take a dependency on the specific version you need.
* ChocolateyForceX86 = If available and set to 'true', then user has requested 32bit version. (0.9.9+) - Automatically handled in built in Choco functions.
* OS_PLATFORM - Like Windows, OSX, Linux. (0.9.9+)
* OS_VERSION - The version of OS, like 6.1 something something for Windows. (0.9.9+)
* OS_NAME - The reported name of the OS. (0.9.9+)
* IS_PROCESSELEVATED = Is the process elevated? (0.9.9+)
* ChocolateyToolsLocation - formerly 'ChocolateyBinRoot' ('ChocolateyBinRoot' will be removed with Chocolatey v2.0.0), this is where tools being installed outside of Chocolatey packaging will go. (0.9.10+)
#### Set By Options and Configuration
Some environment variables are set based on options that are passed, configuration and/or features that are turned on:
* ChocolateyEnvironmentDebug - Was `--debug` passed? If using the built-in PowerShell host, this is always true (but only logs debug messages to console if `--debug` was passed) (0.9.10+)
* ChocolateyEnvironmentVerbose - Was `--verbose` passed? If using the built-in PowerShell host, this is always true (but only logs verbose messages to console if `--verbose` was passed). (0.9.10+)
* ChocolateyForce - Was `--force` passed? (0.9.10+)
* ChocolateyForceX86 - Was `-x86` passed? (CHECK)
* ChocolateyRequestTimeout - How long before a web request will time out. Set by config `webRequestTimeoutSeconds` (CHECK)
* ChocolateyResponseTimeout - How long to wait for a download to complete? Set by config `commandExecutionTimeoutSeconds` (CHECK)
* ChocolateyPowerShellHost - Are we using the built-in PowerShell host? Set by `--use-system-powershell` or the feature `powershellHost` (0.9.10+)
#### Business Edition Variables
* ChocolateyInstallArgumentsSensitive - Encrypted arguments passed from command line `--install-arguments-sensitive` that are not logged anywhere. (0.10.1+ and licensed editions 1.6.0+)
* ChocolateyPackageParametersSensitive - Package parameters passed from command line `--package-parameters-senstivite` that are not logged anywhere. (0.10.1+ and licensed editions 1.6.0+)
* ChocolateyLicensedVersion - What version is the licensed edition on?
* ChocolateyLicenseType - What edition / type of the licensed edition is installed?
#### Experimental Environment Variables
The following are experimental or use not recommended:
* OS_IS64BIT = This may not return correctly - it may depend on the process the app is running under (0.9.9+)
* CHOCOLATEY_VERSION_PRODUCT = the version of Choco that may match CHOCOLATEY_VERSION but may be different (0.9.9+) - based on git describe
* IS_ADMIN = Is the user an administrator? But doesn't tell you if the process is elevated. (0.9.9+)
#### Not Useful Or Anti-Pattern If Used
* ChocolateyInstallOverride = Not for use in package automation scripts. Based on `--override-arguments` being passed. (0.9.9+)
* ChocolateyInstallArguments = The installer arguments meant for the native installer. You should use chocolateyPackageParameters instead. Based on `--install-arguments` being passed. (0.9.9+)
* ChocolateyIgnoreChecksums - Was `--ignore-checksums` passed or the feature `checksumFiles` turned off? (0.9.9.9+)
* ChocolateyAllowEmptyChecksums - Was `--allow-empty-checksums` passed or the feature `allowEmptyChecksums` turned on? (0.10.0+)
* ChocolateyAllowEmptyChecksumsSecure - Was `--allow-empty-checksums-secure` passed or the feature `allowEmptyChecksumsSecure` turned on? (0.10.0+)
* ChocolateyCheckLastExitCode - Should Chocolatey check LASTEXITCODE? Is the feature `scriptsCheckLastExitCode` turned on? (0.10.3+)
* ChocolateyChecksum32 - Was `--download-checksum` passed? (0.10.0+)
* ChocolateyChecksumType32 - Was `--download-checksum-type` passed? (0.10.0+)
* ChocolateyChecksum64 - Was `--download-checksum-x64` passed? (0.10.0)+
* ChocolateyChecksumType64 - Was `--download-checksum-type-x64` passed? (0.10.0)+
* ChocolateyPackageExitCode - The exit code of the script that just ran - usually set by `Set-PowerShellExitCode` (CHECK)
* ChocolateyLastPathUpdate - Set by Chocolatey as part of install, but not used for anything in particular in packaging.
* ChocolateyProxyLocation - The explicit proxy location as set in the configuration `proxy` (0.9.9.9+)
* ChocolateyDownloadCache - Use available download cache? Set by `--skip-download-cache`, `--use-download-cache`, or feature `downloadCache` (0.9.10+ and licensed editions 1.1.0+)
* ChocolateyProxyBypassList - Explicitly set locations to ignore in configuration `proxyBypassList` (0.10.4+)
* ChocolateyProxyBypassOnLocal - Should the proxy bypass on local connections? Set based on configuration `proxyBypassOnLocal` (0.10.4+)
* http_proxy - Set by original `http_proxy` passthrough, or same as `ChocolateyProxyLocation` if explicitly set. (0.10.4+)
* https_proxy - Set by original `https_proxy` passthrough, or same as `ChocolateyProxyLocation` if explicitly set. (0.10.4+)
* no_proxy- Set by original `no_proxy` passthrough, or same as `ChocolateyProxyBypassList` if explicitly set. (0.10.4+)
'@
$global:powerShellReferenceTOC | Out-File $fileName -Encoding UTF8 -Force
Write-Host "Generating command reference markdown files"
Generate-CommandReference 'List' '60'
Generate-CommandReference 'Search' '100'
Generate-CommandReference 'Info' '40'
Generate-CommandReference 'Install' '50'
Generate-CommandReference 'Pin' '90'
Generate-CommandReference 'Outdated' '80'
Generate-CommandReference 'Upgrade' '200'
Generate-CommandReference 'Uninstall' '170'
Generate-CommandReference 'Config' '10'
Generate-CommandReference 'Source' '120'
Generate-CommandReference 'Sources' '130'
Generate-CommandReference 'Feature' '30'
Generate-CommandReference 'Features' '35'
Generate-CommandReference 'New' '10'
Generate-CommandReference 'Pack' '20'
Generate-CommandReference 'ApiKey' '30'
Generate-CommandReference 'SetApiKey' '110'
Generate-CommandReference 'Push' '40'
Generate-CommandReference 'UnpackSelf' '180'
Generate-CommandReference 'Update' '190'
Generate-CommandReference 'Version' '210'
Generate-CommandReference 'Download' '20'
Generate-CommandReference 'Support' '140'
Generate-CommandReference 'Sync' '150'
Generate-CommandReference 'Synchronize' '160'
Generate-CommandReference 'Optimize' '70'
Generate-TopLevelCommandReference
Move-GeneratedFiles
Exit 0
}
catch
{
Throw "Failed to generate documentation. $_"
Exit 255
}