Skip to content

Commit e1b0c12

Browse files
Merge pull request #2 from techthoughts2/Enhancements
added support for graph modules
2 parents 789d13b + c4444e3 commit e1b0c12

File tree

11 files changed

+210
-13
lines changed

11 files changed

+210
-13
lines changed

docs/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [1.1.0]
9+
10+
- Module Changes
11+
- Added support for Azure Graph modules
12+
- Build Updates
13+
- Added `MarkdownRepair.ps1` and added Markdown repair logic to InvokeBuild script.
14+
815
## [1.0.0]
916

1017
- Module Changes

docs/Find-CloudCommand.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ Searches for PowerShell cloud commands matching a given query.
1313
## SYNTAX
1414

1515
```
16-
Find-CloudCommand [-Query] <String> [[-Filter] <String>] [-AllResults] [<CommonParameters>]
16+
Find-CloudCommand [-Query] <String> [[-Filter] <String>] [-AllResults]
17+
[<CommonParameters>]
1718
```
1819

1920
## DESCRIPTION
@@ -126,7 +127,7 @@ Accept wildcard characters: False
126127
```
127128
128129
### CommonParameters
129-
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.
130+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -Verbose, -WarningAction, -WarningVariable, and -ProgressAction.
130131
For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
131132
132133
## INPUTS
@@ -143,4 +144,3 @@ Author: Jake Morrison - @jakemorrison - https://www.techthoughts.info/
143144
[https://github.com/Azure/azure-powershell/blob/main/documentation/azure-powershell-modules.md](https://github.com/Azure/azure-powershell/blob/main/documentation/azure-powershell-modules.md)
144145
145146
[https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/powershell.htm](https://docs.oracle.com/en-us/iaas/Content/API/SDKDocs/powershell.htm)
146-

docs/Get-AllCloudCommandInfo.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Accept wildcard characters: False
5656
```
5757
5858
### CommonParameters
59-
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.
59+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -Verbose, -WarningAction, -WarningVariable, and -ProgressAction.
6060
For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
6161
6262
## INPUTS

docs/Get-CloudCommandFromFile.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ Accept wildcard characters: False
5757
```
5858
5959
### CommonParameters
60-
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable.
60+
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -Verbose, -WarningAction, -WarningVariable, and -ProgressAction.
6161
For more information, see about_CommonParameters (http://go.microsoft.com/fwlink/?LinkID=113216).
6262
6363
## INPUTS

docs/pwshCloudCommands.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Module Name: pwshCloudCommands
33
Module Guid: be3705bf-2c38-413a-8973-9e409e826d35
44
Download Help Link: NA
5-
Help Version: 1.0.0
5+
Help Version: 1.1.0
66
Locale: en-US
77
---
88

src/MarkdownRepair.ps1

Lines changed: 135 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
<#
2+
.SYNOPSIS
3+
Repair PlatyPS generated markdown files.
4+
.NOTES
5+
This file is temporarily required to handle platyPS help generation.
6+
https://github.com/PowerShell/platyPS/issues/595
7+
This is a result of a breaking change introduced in PowerShell 7.4.0:
8+
https://learn.microsoft.com/en-us/powershell/scripting/whats-new/what-s-new-in-powershell-74?view=powershell-7.4
9+
Breaking Changes: Added the ProgressAction parameter to the Common Parameters
10+
modified from source: https://github.com/PowerShell/platyPS/issues/595#issuecomment-1820971702
11+
#>
12+
13+
function Remove-CommonParameterFromMarkdown {
14+
<#
15+
.SYNOPSIS
16+
Remove a PlatyPS generated parameter block.
17+
.DESCRIPTION
18+
Removes parameter block for the provided parameter name from the markdown file provided.
19+
#>
20+
param(
21+
[Parameter(Mandatory)]
22+
[string[]]
23+
$Path,
24+
25+
[Parameter(Mandatory = $false)]
26+
[string[]]
27+
$ParameterName = @('ProgressAction')
28+
)
29+
$ErrorActionPreference = 'Stop'
30+
foreach ($p in $Path) {
31+
$content = (Get-Content -Path $p -Raw).TrimEnd()
32+
$updateFile = $false
33+
foreach ($param in $ParameterName) {
34+
if (-not ($Param.StartsWith('-'))) {
35+
$param = "-$($param)"
36+
}
37+
# Remove the parameter block
38+
$pattern = "(?m)^### $param\r?\n[\S\s]*?(?=#{2,3}?)"
39+
$newContent = $content -replace $pattern, ''
40+
# Remove the parameter from the syntax block
41+
$pattern = " \[$param\s?.*?]"
42+
$newContent = $newContent -replace $pattern, ''
43+
if ($null -ne (Compare-Object -ReferenceObject $content -DifferenceObject $newContent)) {
44+
Write-Verbose "Added $param to $p"
45+
# Update file content
46+
$content = $newContent
47+
$updateFile = $true
48+
}
49+
}
50+
# Save file if content has changed
51+
if ($updateFile) {
52+
$newContent | Out-File -Encoding utf8 -FilePath $p
53+
Write-Verbose "Updated file: $p"
54+
}
55+
}
56+
return
57+
}
58+
59+
function Add-MissingCommonParameterToMarkdown {
60+
param(
61+
[Parameter(Mandatory)]
62+
[string[]]
63+
$Path,
64+
65+
[Parameter(Mandatory = $false)]
66+
[string[]]
67+
$ParameterName = @('ProgressAction')
68+
)
69+
$ErrorActionPreference = 'Stop'
70+
foreach ($p in $Path) {
71+
$content = (Get-Content -Path $p -Raw).TrimEnd()
72+
$updateFile = $false
73+
foreach ($NewParameter in $ParameterName) {
74+
if (-not ($NewParameter.StartsWith('-'))) {
75+
$NewParameter = "-$($NewParameter)"
76+
}
77+
$pattern = '(?m)^This cmdlet supports the common parameters:(.+?)\.'
78+
$replacement = {
79+
$Params = $_.Groups[1].Captures[0].ToString() -split ' '
80+
$CommonParameters = @()
81+
foreach ($CommonParameter in $Params) {
82+
if ($CommonParameter.StartsWith('-')) {
83+
if ($CommonParameter.EndsWith(',')) {
84+
$CleanParam = $CommonParameter.Substring(0, $CommonParameter.Length - 1)
85+
}
86+
elseif ($p.EndsWith('.')) {
87+
$CleanParam = $CommonParameter.Substring(0, $CommonParameter.Length - 1)
88+
}
89+
else {
90+
$CleanParam = $CommonParameter
91+
}
92+
$CommonParameters += $CleanParam
93+
}
94+
}
95+
if ($NewParameter -notin $CommonParameters) {
96+
$CommonParameters += $NewParameter
97+
}
98+
$CommonParameters[-1] = "and $($CommonParameters[-1]). "
99+
return "This cmdlet supports the common parameters: " + (($CommonParameters | Sort-Object) -join ', ')
100+
}
101+
$newContent = $content -replace $pattern, $replacement
102+
if ($null -ne (Compare-Object -ReferenceObject $content -DifferenceObject $newContent)) {
103+
Write-Verbose "Added $NewParameter to $p"
104+
$updateFile = $true
105+
$content = $newContent
106+
}
107+
}
108+
# Save file if content has changed
109+
if ($updateFile) {
110+
$newContent | Out-File -Encoding utf8 -FilePath $p
111+
Write-Verbose "Updated file: $p"
112+
}
113+
}
114+
return
115+
}
116+
117+
function Repair-PlatyPSMarkdown {
118+
param(
119+
[Parameter(Mandatory)]
120+
[string[]]
121+
$Path,
122+
123+
[Parameter()]
124+
[string[]]
125+
$ParameterName = @('ProgressAction')
126+
)
127+
$ErrorActionPreference = 'Stop'
128+
$Parameters = @{
129+
Path = $Path
130+
ParameterName = $ParameterName
131+
}
132+
$null = Remove-CommonParameterFromMarkdown @Parameters
133+
$null = Add-MissingCommonParameterToMarkdown @Parameters
134+
return
135+
}

src/Tests/Integration/pwshCloudCommands.Infra.Tests.ps1

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ InModuleScope 'pwshCloudCommands' {
4040
$eval.Count | Should -BeGreaterThan 20
4141
} #it
4242

43+
It 'should return expected results for graph module query' {
44+
$eval = Find-CloudCommand -Query 'Get-MgUser' -Filter Azure
45+
$eval.ModuleName | Should -BeExactly 'Microsoft.Graph.Users'
46+
} #it
47+
48+
It 'should return expected results for oracle module query' {
49+
$eval = Find-CloudCommand -Query 'New-OCIComputeInstance' -Filter Oracle
50+
$eval.ModuleName | Should -BeExactly 'OCI.PSModules.Core'
51+
} #it
52+
4353
} #context_Find-CloudCommand
4454
Context 'Get-CloudCommandFromFile' {
4555

src/Tests/Unit/Private/Search-XMLDataSet.Tests.ps1

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -161,17 +161,28 @@ in order to stop getting charged for the storage of uploaded parts, you should
161161
$xmlObj
162162
} -Verifiable
163163
Search-XMLDataSet -Query $cleanQuery -Filter AWS
164+
164165
Assert-VerifiableMock
166+
Should -Invoke -CommandName Get-ChildItem -Times 1 -Exactly
165167
} #it
166168

167169
It 'should filter properly for Azure based on user input' {
168-
Mock -CommandName Get-ChildItem {
169-
$Filter | Should -BeExactly 'Az.*'
170-
# $ErrorAction | Should -BeExactly 'Stop'
171-
$xmlObj
172-
} -Verifiable
170+
$script:mockCalled = 0
171+
Mock -CommandName Get-ChildItem -MockWith {
172+
$script:mockCalled++
173+
if ($script:mockCalled -eq 1) {
174+
$Filter | Should -BeExactly 'Az.*'
175+
}
176+
elseif ($script:mockCalled -eq 2) {
177+
$Filter | Should -BeExactly 'Microsoft.Graph.*'
178+
}
179+
# Return a mock XML object or similar to simulate the command's output
180+
return $mockXmlObj
181+
}
182+
173183
Search-XMLDataSet -Query $cleanQuery -Filter Azure
174-
Assert-VerifiableMock
184+
185+
Should -Invoke -CommandName Get-ChildItem -Times 2 -Exactly
175186
} #it
176187

177188
It 'should filter properly for Oracle based on user input' {
@@ -181,7 +192,9 @@ in order to stop getting charged for the storage of uploaded parts, you should
181192
$xmlObj
182193
} -Verifiable
183194
Search-XMLDataSet -Query $cleanQuery -Filter Oracle
195+
184196
Assert-VerifiableMock
197+
Should -Invoke -CommandName Get-ChildItem -Times 1 -Exactly
185198
} #it
186199

187200
It 'should filter properly for free form query based on user input' {
@@ -191,7 +204,9 @@ in order to stop getting charged for the storage of uploaded parts, you should
191204
$xmlObj
192205
} -Verifiable
193206
Search-XMLDataSet -Query $cleanQuery
207+
194208
Assert-VerifiableMock
209+
Should -Invoke -CommandName Get-ChildItem -Times 1 -Exactly
195210
} #it
196211

197212
} #context_Filter

src/pwshCloudCommands.build.ps1

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,17 @@ Add-BuildTask CreateMarkdownHelp -After CreateHelpStart {
380380
throw 'Missing GUID. Please review and rebuild.'
381381
}
382382

383+
Write-Build Gray ' Evaluating if running 7.4.0 or higher...'
384+
# https://github.com/PowerShell/platyPS/issues/595
385+
if ($PSVersionTable.PSVersion -ge [version]'7.4.0') {
386+
Write-Build Gray ' Performing Markdown repair'
387+
# dot source markdown repair
388+
. $BuildRoot\MarkdownRepair.ps1
389+
$OutputDir | Get-ChildItem -File | ForEach-Object {
390+
Repair-PlatyPSMarkdown -Path $_.FullName
391+
}
392+
}
393+
383394
Write-Build Gray ' Checking for missing documentation in md files...'
384395
$MissingDocumentation = Select-String -Path "$script:ArtifactsPath\docs\*.md" -Pattern "({{.*}})"
385396
if ($MissingDocumentation.Count -gt 0) {

src/pwshCloudCommands/Private/Search-XMLDataSet.ps1

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,25 @@ function Search-XMLDataSet {
106106
throw
107107
}
108108

109+
# special case for Azure selection where we will also retrieve Graph Modules
110+
if ($Filter -eq 'Azure') {
111+
Write-Debug -Message 'Retrieving Azure Graph xml file info...'
112+
$getChildItemSplat = @{
113+
Path = $xmlDataPath
114+
Filter = 'Microsoft.Graph.*'
115+
ErrorAction = 'Stop'
116+
}
117+
try {
118+
$graphFiles = Get-ChildItem @getChildItemSplat
119+
}
120+
catch {
121+
Write-Warning -Message 'An error was encountered getting xml file info.'
122+
Write-Error $_
123+
throw
124+
}
125+
$xmlDataFiles += $graphFiles
126+
}
127+
109128
Write-Verbose -Message 'Running query...'
110129
if ($PSCmdlet.ParameterSetName -eq 'Function') {
111130
#------------------------------

0 commit comments

Comments
 (0)