diff --git a/Docs/Help/Add-AzDataTableEntity.md b/Docs/Help/Add-AzDataTableEntity.md index ea1fbdb..741bce9 100644 --- a/Docs/Help/Add-AzDataTableEntity.md +++ b/Docs/Help/Add-AzDataTableEntity.md @@ -113,7 +113,7 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS @@ -127,7 +127,7 @@ This cmdlet takes either an array of hashtables or psobjects as input to the Ent ## NOTES -### Regarding Dates, DateTime, and DateTimeOffset +Regarding Dates, DateTime, and DateTimeOffset: The underlying Azure.Data.Tables SDK expects to work with DateTime fields in UTC format for conversion to DateTimeOffset objects. When submitting a DateTimeOffset object to the SDK, it will be converted to UTC timezone rather than preserving the existing timezone/offset info. Similarly, if a `DateTime` object is submitted in the entity with its Kind set to "local" or "unspecified", the SDK will return an error and state that `Azure SDK requires it to be UTC`. While there isn't any change needed to get `DateTimeOffset` objects to work with AzBobbyTables, the workaround for `DateTime` objects is to set the property to a new `DateTime` object with its `Kind` property set to `Utc`. e.g. `$obj.Time = $obj.Time.ToUniversalFormat()`. [Related issue](https://github.com/Azure/azure-sdk-for-net/issues/30644). diff --git a/Docs/Help/Clear-AzDataTable.md b/Docs/Help/Clear-AzDataTable.md index 5456adf..ff25849 100644 --- a/Docs/Help/Clear-AzDataTable.md +++ b/Docs/Help/Clear-AzDataTable.md @@ -60,7 +60,7 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/Docs/Help/Get-AzDataTableEntity.md b/Docs/Help/Get-AzDataTableEntity.md index 45ae5fd..681822e 100644 --- a/Docs/Help/Get-AzDataTableEntity.md +++ b/Docs/Help/Get-AzDataTableEntity.md @@ -21,7 +21,8 @@ Get-AzDataTableEntity -Context [-Filter ] [-Propert ### Count ``` -Get-AzDataTableEntity -Context [-Count] [] +Get-AzDataTableEntity -Context [-Count] + [] ``` ## DESCRIPTION @@ -186,7 +187,7 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/Docs/Help/New-AzDataTable.md b/Docs/Help/New-AzDataTable.md index 4606d4f..db0daff 100644 --- a/Docs/Help/New-AzDataTable.md +++ b/Docs/Help/New-AzDataTable.md @@ -51,7 +51,7 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/Docs/Help/New-AzDataTableContext.md b/Docs/Help/New-AzDataTableContext.md index 762686a..8b13042 100644 --- a/Docs/Help/New-AzDataTableContext.md +++ b/Docs/Help/New-AzDataTableContext.md @@ -15,12 +15,14 @@ Creates a context object with authentication information for the table to operat ### ConnectionString ``` -New-AzDataTableContext -TableName -ConnectionString [] +New-AzDataTableContext -TableName -ConnectionString + [] ``` ### SAS ``` -New-AzDataTableContext -TableName -SharedAccessSignature [] +New-AzDataTableContext -TableName -SharedAccessSignature + [] ``` ### Key @@ -31,12 +33,14 @@ New-AzDataTableContext -TableName -StorageAccountName -Storage ### Token ``` -New-AzDataTableContext -TableName -StorageAccountName -Token [] +New-AzDataTableContext -TableName -StorageAccountName -Token + [] ``` ### ManagedIdentity ``` -New-AzDataTableContext -TableName -StorageAccountName [-ManagedIdentity] [] +New-AzDataTableContext -TableName -StorageAccountName [-ManagedIdentity] + [] ``` ## DESCRIPTION @@ -200,7 +204,7 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/Docs/Help/Remove-AzDataTable.md b/Docs/Help/Remove-AzDataTable.md index af8826f..46af468 100644 --- a/Docs/Help/Remove-AzDataTable.md +++ b/Docs/Help/Remove-AzDataTable.md @@ -51,7 +51,7 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/Docs/Help/Remove-AzDataTableEntity.md b/Docs/Help/Remove-AzDataTableEntity.md index d70350d..db29441 100644 --- a/Docs/Help/Remove-AzDataTableEntity.md +++ b/Docs/Help/Remove-AzDataTableEntity.md @@ -14,7 +14,8 @@ Remove one or more entities from an Azure Table. ## SYNTAX ``` -Remove-AzDataTableEntity -Context -Entity [] +Remove-AzDataTableEntity -Context -Entity + [] ``` ## DESCRIPTION @@ -85,7 +86,7 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/Docs/Help/Update-AzDataTableEntity.md b/Docs/Help/Update-AzDataTableEntity.md index 54dba6c..a5be554 100644 --- a/Docs/Help/Update-AzDataTableEntity.md +++ b/Docs/Help/Update-AzDataTableEntity.md @@ -14,7 +14,8 @@ Update one or more entities in an Azure Table. ## SYNTAX ``` -Update-AzDataTableEntity -Context -Entity [] +Update-AzDataTableEntity -Context -Entity + [] ``` ## DESCRIPTION @@ -72,7 +73,7 @@ Accept wildcard characters: False ``` ### CommonParameters -This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). +This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutBuffer, -OutVariable, -PipelineVariable, -ProgressAction, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216). ## INPUTS diff --git a/Scripts/PlatyPSWorkaround.ps1 b/Scripts/PlatyPSWorkaround.ps1 new file mode 100644 index 0000000..6079221 --- /dev/null +++ b/Scripts/PlatyPSWorkaround.ps1 @@ -0,0 +1,126 @@ +# Workaround to run post-build to avoid platyPS generating documentation for common parameter ProgressAction +# From issue comment https://github.com/PowerShell/platyPS/issues/595#issuecomment-1850775410 +function Remove-CommonParameterFromMarkdown { + <# + .SYNOPSIS + Remove a PlatyPS generated parameter block. + + .DESCRIPTION + Removes parameter block for the provided parameter name from the markdown file provided. + + #> + param( + [Parameter(Mandatory)] + [string[]] + $Path, + + [Parameter(Mandatory = $false)] + [string[]] + $ParameterName = @('ProgressAction') + ) + $ErrorActionPreference = 'Stop' + foreach ($p in $Path) { + $content = (Get-Content -Path $p -Raw).TrimEnd() + $updateFile = $false + foreach ($param in $ParameterName) { + if (-not ($Param.StartsWith('-'))) { + $param = "-$($param)" + } + # Remove the parameter block + $pattern = "(?m)^### $param\r?\n[\S\s]*?(?=#{2,3}?)" + $newContent = $content -replace $pattern, '' + # Remove the parameter from the syntax block + $pattern = " \[$param\s?.*?]" + $newContent = $newContent -replace $pattern, '' + if ($null -ne (Compare-Object -ReferenceObject $content -DifferenceObject $newContent)) { + Write-Verbose "Added $param to $p" + # Update file content + $content = $newContent + $updateFile = $true + } + } + # Save file if content has changed + if ($updateFile) { + $newContent | Out-File -Encoding utf8 -FilePath $p + Write-Verbose "Updated file: $p" + } + } + return +} + +function Add-MissingCommonParameterToMarkdown { + param( + [Parameter(Mandatory)] + [string[]] + $Path, + + [Parameter(Mandatory = $false)] + [string[]] + $ParameterName = @('ProgressAction') + ) + $ErrorActionPreference = 'Stop' + foreach ($p in $Path) { + $content = (Get-Content -Path $p -Raw).TrimEnd() + $updateFile = $false + foreach ($NewParameter in $ParameterName) { + if (-not ($NewParameter.StartsWith('-'))) { + $NewParameter = "-$($NewParameter)" + } + $pattern = '(?m)^This cmdlet supports the common parameters:(.+?)\.' + $replacement = { + $Params = $_.Groups[1].Captures[0].ToString() -split ' ' + $CommonParameters = @() + foreach ($CommonParameter in $Params) { + if ($CommonParameter.StartsWith('-')) { + if ($CommonParameter.EndsWith(',')) { + $CleanParam = $CommonParameter.Substring(0, $CommonParameter.Length -1) + } elseif ($p.EndsWith('.')) { + $CleanParam = $CommonParameter.Substring(0, $CommonParameter.Length -1) + } else{ + $CleanParam = $CommonParameter + } + $CommonParameters += $CleanParam + } + } + if ($NewParameter -notin $CommonParameters) { + $CommonParameters += $NewParameter + } + $CommonParameters = ($CommonParameters | Sort-Object) + $CommonParameters[-1] = "and $($CommonParameters[-1])." + return "This cmdlet supports the common parameters: " + (($CommonParameters) -join ', ') + } + $newContent = $content -replace $pattern, $replacement + if ($null -ne (Compare-Object -ReferenceObject $content -DifferenceObject $newContent)) { + Write-Verbose "Added $NewParameter to $p" + $updateFile = $true + $content = $newContent + } + } + # Save file if content has changed + if ($updateFile) { + $newContent | Out-File -Encoding utf8 -FilePath $p + Write-Verbose "Updated file: $p" + } + } + return +} + +function Repair-PlatyPSMarkdown { + param( + [Parameter(Mandatory)] + [string[]] + $Path, + + [Parameter()] + [string[]] + $ParameterName = @('ProgressAction') + ) + $ErrorActionPreference = 'Stop' + $Parameters = @{ + Path = $Path + ParameterName = $ParameterName + } + $null = Remove-CommonParameterFromMarkdown @Parameters + $null = Add-MissingCommonParameterToMarkdown @Parameters + return +} \ No newline at end of file diff --git a/Scripts/SetReleaseDraft.ps1 b/Scripts/SetReleaseDraft.ps1 index cf92038..d1ab8fe 100644 --- a/Scripts/SetReleaseDraft.ps1 +++ b/Scripts/SetReleaseDraft.ps1 @@ -40,7 +40,7 @@ $PullRequest = Invoke-RestMethod -Uri "$URL/pulls/$PRNumber" $PRLabels = $PullRequest.labels.name Write-Verbose 'Found Pull Request' Write-Verbose "PR Number: $($PullRequest.number)" -Write-Verbose "PR Label: $PRLabel" +Write-Verbose "PR Label: $PRLabels" Write-Verbose "PR Author: $($PullRequest.user.login)" # Commit details diff --git a/Source/AzBobbyTables.Core/AzDataTableService.cs b/Source/AzBobbyTables.Core/AzDataTableService.cs index 389832a..4ec4c84 100644 --- a/Source/AzBobbyTables.Core/AzDataTableService.cs +++ b/Source/AzBobbyTables.Core/AzDataTableService.cs @@ -11,12 +11,12 @@ namespace PipeHow.AzBobbyTables.Core; public class AzDataTableService { - private TableClient tableClient { get; set; } + private TableClient TableClient { get; set; } /// /// Cancellation token used within the AzDataTableService. /// - private CancellationToken cancellationToken { get; } + private CancellationToken CancellationToken { get; } /// /// List of supported data types for the table. @@ -36,7 +36,7 @@ public class AzDataTableService "string" }; - private AzDataTableService(CancellationToken cancellationToken) => this.cancellationToken = cancellationToken; + private AzDataTableService(CancellationToken cancellationToken) => CancellationToken = cancellationToken; private static void CreateIfNotExists(TableClient client, CancellationToken cancellationToken) { @@ -56,14 +56,14 @@ public static AzDataTableService CreateWithConnectionString(string connectionStr { var dataTableService = new AzDataTableService(cancellationToken); - TableClient client = new TableClient(connectionString, tableName); + TableClient client = new(connectionString, tableName); if (createIfNotExists) { CreateIfNotExists(client, cancellationToken); } - dataTableService.tableClient = client; + dataTableService.TableClient = client; return dataTableService; } catch (Exception ex) @@ -79,14 +79,14 @@ public static AzDataTableService CreateWithStorageKey(string storageAccountName, var bobbyService = new AzDataTableService(cancellationToken); var tableEndpoint = new Uri($"https://{storageAccountName}.table.core.windows.net/{tableName}"); - TableClient client = new TableClient(tableEndpoint, tableName, new TableSharedKeyCredential(storageAccountName, storageAccountKey)); + TableClient client = new(tableEndpoint, tableName, new TableSharedKeyCredential(storageAccountName, storageAccountKey)); if (createIfNotExists) { CreateIfNotExists(client, cancellationToken); } - bobbyService.tableClient = client; + bobbyService.TableClient = client; return bobbyService; } catch (Exception ex) @@ -102,14 +102,14 @@ public static AzDataTableService CreateWithToken(string storageAccountName, stri var bobbyService = new AzDataTableService(cancellationToken); var tableEndpoint = new Uri($"https://{storageAccountName}.table.core.windows.net/{tableName}"); - TableClient client = new TableClient(tableEndpoint, tableName, new ExternalTokenCredential(token, DateTimeOffset.Now.Add(TimeSpan.FromHours(1)))); + TableClient client = new(tableEndpoint, tableName, new ExternalTokenCredential(token, DateTimeOffset.Now.Add(TimeSpan.FromHours(1)))); if (createIfNotExists) { CreateIfNotExists(client, cancellationToken); } - bobbyService.tableClient = client; + bobbyService.TableClient = client; return bobbyService; } catch (Exception ex) @@ -134,14 +134,14 @@ public static AzDataTableService CreateWithSAS(Uri sasUrl, string tableName, boo sasUrl = new Uri($"{urlParts.First()}{tableName}?{urlParts.Last()}"); } - TableClient client = new TableClient(sasUrl, sasCredential); + TableClient client = new(sasUrl, sasCredential); if (createIfNotExists) { CreateIfNotExists(client, cancellationToken); } - dataTableService.tableClient = client; + dataTableService.TableClient = client; return dataTableService; } catch (Exception ex) @@ -154,7 +154,7 @@ public void RemoveTable() { try { - tableClient.Delete(); + TableClient.Delete(); } catch (Exception ex) { @@ -368,7 +368,7 @@ public IEnumerable GetEntitiesFromTable(string query, string[] propert try { // Declare type as IAsyncEnumerable to be able to overwrite it with LINQ results further down - IAsyncEnumerable entities = tableClient.QueryAsync(query, null, properties, cancellationToken); + IAsyncEnumerable entities = TableClient.QueryAsync(query, null, properties, CancellationToken); // If user specified one or more properties to sort list by // This may slow the query down a lot with a lot of results @@ -422,7 +422,7 @@ public void ClearTable() { try { - var entities = tableClient.Query((string)null, null, new[] { "PartitionKey", "RowKey" }); + var entities = TableClient.Query((string)null, null, new[] { "PartitionKey", "RowKey" }); var transactions = new List(); @@ -448,7 +448,11 @@ private void SubmitTransaction(IList transactions) // Loop through each group and submit up to 100 at a time for (int i = 0; i < group.Count(); i += 100) { - tableClient.SubmitTransaction(group.Skip(i).Take(100), cancellationToken); + var response = TableClient.SubmitTransaction(group.Skip(i).Take(100), CancellationToken); + foreach (var transactionResult in response.Value) + { + Console.WriteLine(transactionResult.Content.ToString()); + } } } } diff --git a/Tests/Module.Tests.ps1 b/Tests/Module.Tests.ps1 index d747c82..263aef6 100644 --- a/Tests/Module.Tests.ps1 +++ b/Tests/Module.Tests.ps1 @@ -57,7 +57,7 @@ Describe "$ModuleName" { } It 'has no help file with empty documentation sections' { - Get-ChildItem "$RootDirectory\Docs\Help\*.md" | Select-String '{{|}}' | Should -BeNullOrEmpty + Get-ChildItem "$RootDirectory\Docs\Help\*.md" | Select-String '{{ Fill \w+ Description }}' | Should -BeNullOrEmpty } It 'has command defined in file in the correct directory' -TestCases $CommandTestCases { diff --git a/build.ps1 b/build.ps1 index f4f483f..f98991e 100644 --- a/build.ps1 +++ b/build.ps1 @@ -76,6 +76,11 @@ Pop-Location # Run markdown file updates and tests in separate PowerShell sessions to avoid module load assembly locking & pwsh -c "Import-Module '$OutDir\$ModuleName.psd1'; Update-MarkdownHelpModule -Path '$PSScriptRoot\Docs\Help'" + +# Workaround to run post-build to avoid platyPS generating documentation for common parameter ProgressAction +. "$PSScriptRoot\Scripts\PlatyPSWorkaround.ps1" +Repair-PlatyPSMarkdown -Path (Get-ChildItem "$PSScriptRoot\Docs\Help") -ParameterName 'ProgressAction' + if ($RunTests -ne 'None') { & pwsh -c ".\Tests\TestRunner.ps1 -SkipIntegration:`$$($RunTests -eq 'SkipIntegration')" }