Skip to content

Commit a8d80c9

Browse files
committed
Resolve code review feedback
1 parent 37502bf commit a8d80c9

File tree

1 file changed

+29
-54
lines changed

1 file changed

+29
-54
lines changed

tools/platyPSHelp/platyPSHelp.psm1

Lines changed: 29 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ function New-ServiceMarkdownHelp
1515
[ValidateSet("Debug", "Release")]
1616
[String]$BuildTarget,
1717

18-
[Parameter(ParameterSetName="ResourceManager", Mandatory=$True)]
19-
[Parameter(ParameterSetName="ServiceManagement", Mandatory=$True)]
20-
[Parameter(ParameterSetName="Storage", Mandatory=$True)]
21-
[String]$PathToRepo,
22-
2318
[Parameter(ParameterSetName="ResourceManager", Mandatory=$True)]
2419
[Switch]$ResourceManager,
2520

@@ -33,37 +28,40 @@ function New-ServiceMarkdownHelp
3328
[String]$PathToModule,
3429

3530
[Parameter(ParameterSetName="FullPath", Mandatory=$True)]
36-
[String]$PathToCommandsFolder,
37-
38-
[Parameter(ParameterSetName="FullPath", Mandatory=$True)]
39-
[String]$ModuleName
31+
[String]$PathToCommandsFolder
4032
)
4133

4234
PROCESS
4335
{
36+
# Get the path to the platyPSHelp module root
37+
$PSModule = $ExecutionContext.SessionState.Module
38+
$PSModuleRoot = $PSModule.ModuleBase
39+
40+
# Use the platyPSHelp module root to get the path to the repository
41+
$PathToRepo = (Get-Item $PSModuleRoot).Parent.Parent.FullName
42+
4443
# Set the necessary variables for an ARM service
4544
if ($ResourceManager.IsPresent)
4645
{
4746
$PathToModule = "$PathToRepo\src\Package\$BuildTarget\ResourceManager\AzureResourceManager\AzureRM.$Service\AzureRM.$Service.psd1"
4847
$PathToCommandsFolder = "$PathToRepo\src\ResourceManager\$Service\Commands.$Service"
49-
$ModuleName = "AzureRM.$Service"
5048
}
5149
# Set the necessary variables for an RDFE service
5250
elseif ($ServiceManagement.IsPresent)
5351
{
5452
throw "Currently platyPSHelp is unavailable for RDFE services. Please refer to the platyps-help.md documentation for more information."
5553
$PathToModule = Get-ServiceManagementDll -Service $Service -PathToAzure "$PathToRepo\src\Package\$BuildTarget\ServiceManagement\Azure"
5654
$PathToCommandsFolder = "$PathToRepo\src\ServiceManagement\$Service\Commands.$Service"
57-
$ModuleName = Get-ServiceManagementModuleName -PathToModule $PathToModule
5855
}
5956
# Set the necessary variables for Storage
6057
elseif ($Storage.IsPresent)
6158
{
6259
$PathToModule = "$PathToRepo\src\Package\$BuildTarget\Storage\Azure.Storage\Azure.Storage.psd1"
6360
$PathToCommandsFolder = "$PathToRepo\src\Storage\Commands.Storage"
64-
$ModuleName = "Azure.Storage"
6561
}
6662

63+
$ModuleName = (Get-Item $PathToModule).BaseName
64+
6765
# If the "FullPath" parameter set is not used, make sure the paths created above are accessible
6866
if (!($PSCmdlet.ParameterSetName -eq "FullPath"))
6967
{
@@ -154,11 +152,6 @@ function Update-ServiceMarkdownHelp
154152
[ValidateSet("Debug", "Release")]
155153
[String]$BuildTarget,
156154

157-
[Parameter(ParameterSetName="ResourceManager", Mandatory=$True)]
158-
[Parameter(ParameterSetName="ServiceManagement", Mandatory=$True)]
159-
[Parameter(ParameterSetName="Storage", Mandatory=$True)]
160-
[String]$PathToRepo,
161-
162155
[Parameter(ParameterSetName="ResourceManager", Mandatory=$True)]
163156
[Switch]$ResourceManager,
164157

@@ -172,37 +165,40 @@ function Update-ServiceMarkdownHelp
172165
[String]$PathToModule,
173166

174167
[Parameter(ParameterSetName="FullPath", Mandatory=$True)]
175-
[String]$PathToCommandsFolder,
176-
177-
[Parameter(ParameterSetName="FullPath", Mandatory=$True)]
178-
[String]$ModuleName
168+
[String]$PathToCommandsFolder
179169
)
180170

181-
PROCESS
171+
PROCESS
182172
{
173+
# Get the path to the platyPSHelp module root
174+
$PSModule = $ExecutionContext.SessionState.Module
175+
$PSModuleRoot = $PSModule.ModuleBase
176+
177+
# Use the platyPSHelp module root to get the path to the repository
178+
$PathToRepo = (Get-Item $PSModuleRoot).Parent.Parent.FullName
179+
183180
# Set the necessary variables for an ARM service
184181
if ($ResourceManager.IsPresent)
185182
{
186183
$PathToModule = "$PathToRepo\src\Package\$BuildTarget\ResourceManager\AzureResourceManager\AzureRM.$Service\AzureRM.$Service.psd1"
187184
$PathToCommandsFolder = "$PathToRepo\src\ResourceManager\$Service\Commands.$Service"
188-
$ModuleName = "AzureRM.$Service"
189185
}
190186
# Set the necessary variables for an RDFE service
191187
elseif ($ServiceManagement.IsPresent)
192188
{
193189
throw "Currently platyPSHelp is unavailable for RDFE services. Please refer to the platyps-help.md documentation for more information."
194190
$PathToModule = "$PathToRepo\src\Package\$BuildTarget\ServiceManagement\Azure\Azure.psd1"
195191
$PathToCommandsFolder = "$PathToRepo\src\ServiceManagement\$Service\Commands.$Service"
196-
$ModuleName = "Azure"
197192
}
198193
# Set the necessary variables for Storage
199194
elseif ($Storage.IsPresent)
200195
{
201196
$PathToModule = "$PathToRepo\src\Package\$BuildTarget\Storage\Azure.Storage\Azure.Storage.psd1"
202197
$PathToCommandsFolder = "$PathToRepo\src\Storage\Commands.Storage"
203-
$ModuleName = "Azure.Storage"
204198
}
205199

200+
$ModuleName = (Get-Item $PathToModule).BaseName
201+
206202
# If the "FullPath" parameter set is not used, make sure the paths created above are accessible
207203
if (!($PSCmdlet.ParameterSetName -eq "FullPath"))
208204
{
@@ -223,7 +219,7 @@ function Update-ServiceMarkdownHelp
223219
Import-Module $PathToModule -Scope Global
224220

225221
# Update the markdown files with the changes made in the cmdlets
226-
Update-MarkdownHelpModule $PathToHelp -AlphabeticParamsOrder
222+
Update-MarkdownHelpModule $PathToHelp -AlphabeticParamsOrder -RefreshModulePage
227223

228224
# Generate the MAML help file from the markdown files
229225
New-ServiceExternalHelp -PathToCommandsFolder $PathToCommandsFolder
@@ -327,29 +323,6 @@ function Get-ServiceManagementDll
327323
throw "Unable to find dll for the given service."
328324
}
329325

330-
function Get-ServiceManagementModuleName
331-
{
332-
[CmdletBinding()]
333-
Param(
334-
[Parameter(Mandatory=$True)]
335-
[String]$PathToModule
336-
)
337-
338-
for (;;)
339-
{
340-
if ($PathToModule.IndexOf("\") -lt 0)
341-
{
342-
break
343-
}
344-
345-
$idx = $PathToModule.IndexOf("\")
346-
$PathToModule = $PathToModule.Substring($idx + 1)
347-
}
348-
349-
$idx = $PathToModule.IndexOf(".dll")
350-
return $PathToModule.Substring(0, $idx)
351-
}
352-
353326
<#
354327
.ExternalHelp help\platyPSHelp-help.xml
355328
#>
@@ -361,11 +334,6 @@ function Validate-ServiceMarkdownHelp
361334
[Parameter(ParameterSetName="ServiceManagement", Mandatory=$True)]
362335
[String]$Service,
363336

364-
[Parameter(ParameterSetName="ResourceManager", Mandatory=$True)]
365-
[Parameter(ParameterSetName="ServiceManagement", Mandatory=$True)]
366-
[Parameter(ParameterSetName="Storage", Mandatory=$True)]
367-
[String]$PathToRepo,
368-
369337
[Parameter(ParameterSetName="ResourceManager", Mandatory=$True)]
370338
[Switch]$ResourceManager,
371339

@@ -384,6 +352,13 @@ function Validate-ServiceMarkdownHelp
384352

385353
PROCESS
386354
{
355+
# Get the path to the platyPSHelp module root
356+
$PSModule = $ExecutionContext.SessionState.Module
357+
$PSModuleRoot = $PSModule.ModuleBase
358+
359+
# Use the platyPSHelp module root to get the path to the repository
360+
$PathToRepo = (Get-Item $PSModuleRoot).Parent.Parent.FullName
361+
387362
# Set the necessary variables for an ARM service
388363
if ($ResourceManager.IsPresent)
389364
{

0 commit comments

Comments
 (0)