Skip to content

Commit 2123c46

Browse files
authored
[Eng] Remove 'ProgressAction' while build autorest modules (Azure#27394)
1 parent 9e3c891 commit 2123c46

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

tools/BuildScripts/AdaptAutorestModule.ps1

+4
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ try{
182182
[string]$SubModuleNameTrimmed
183183
)
184184

185+
$helpMarkDownScriptPath = Join-Path $RepoRoot 'tools' 'BuildScripts' 'HelpMarkDown.psm1'
186+
Import-Module $helpMarkDownScriptPath
185187
$resolveScriptPath = Join-Path $RepoRoot 'tools' 'ResolveTools' 'Resolve-Psd1.ps1'
186188
$artifacts = Join-Path $RepoRoot 'artifacts'
187189
$artifactAccountPsd1Path = Join-Path $artifacts 'Debug' "Az.Accounts" "Az.Accounts.psd1"
@@ -219,6 +221,8 @@ try{
219221
Write-Host "Redundant help markdown detected, removing $helpFile ..."
220222
Remove-Item $helpFile.FullName -Force
221223
}
224+
Write-Host "Removing ProgressAction parameter from $helpFile ..."
225+
Remove-CommonParameterFromMarkdown -Path $helpFile.FullName -ParameterName 'ProgressAction'
222226
}
223227
& $resolveScriptPath -ModuleName $ModuleRootName -ArtifactFolder $artifacts -Psd1Folder $parentModulePath
224228
} -ArgumentList $RepoRoot, $ModuleRootName, $parentModuleName, $SubModuleName, $subModuleNameTrimmed

tools/BuildScripts/HelpMarkDown.psm1

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# Copied from https://gist.github.com/wyunchi-ms/098996d35e1f98388837fa31aaaa6f62
2+
function Remove-CommonParameterFromMarkdown {
3+
<#
4+
.SYNOPSIS
5+
Remove a PlatyPS generated parameter block.
6+
.DESCRIPTION
7+
Removes parameter block for the provided parameter name from the markdown file provided.
8+
#>
9+
param(
10+
[Parameter(Mandatory)]
11+
[string[]]
12+
$Path,
13+
14+
[Parameter(Mandatory = $false)]
15+
[string[]]
16+
$ParameterName = @('ProgressAction')
17+
)
18+
$ErrorActionPreference = 'Stop'
19+
foreach ($p in $Path) {
20+
$content = (Get-Content -Path $p -Raw).TrimEnd()
21+
$updateFile = $false
22+
foreach ($param in $ParameterName) {
23+
if (-not ($Param.StartsWith('-'))) {
24+
$param = "-$($param)"
25+
}
26+
# Remove the parameter block
27+
$pattern = "(?m)^### $param\r?\n[\S\s]*?(?=#{2,3}?)"
28+
$newContent = $content -replace $pattern, ''
29+
# Remove the parameter from the syntax block
30+
$pattern = " \[$param\s?.*?]"
31+
$newContent = $newContent -replace $pattern, ''
32+
if ($null -ne (Compare-Object -ReferenceObject $content -DifferenceObject $newContent)) {
33+
Write-Verbose "Added $param to $p"
34+
# Update file content
35+
$content = $newContent
36+
$updateFile = $true
37+
}
38+
}
39+
# Save file if content has changed
40+
if ($updateFile) {
41+
$newContent | Out-File -Encoding utf8 -FilePath $p
42+
Write-Verbose "Updated file: $p"
43+
}
44+
}
45+
return
46+
}

0 commit comments

Comments
 (0)