-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from awickham10/development
Fix Add-DpaAnnotation
- Loading branch information
Showing
33 changed files
with
680 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Tests/Constants.Local.ps1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
function Invoke-DpaFormatter { | ||
<# | ||
.SYNOPSIS | ||
Helps formatting function files to dbatools' standards | ||
.DESCRIPTION | ||
Uses PSSA's Invoke-Formatter to format the target files and saves it without the BOM. | ||
.PARAMETER Path | ||
The path to the ps1 file that needs to be formatted | ||
.PARAMETER EnableException | ||
By default, when something goes wrong we try to catch it, interpret it and give you a friendly warning message. | ||
This avoids overwhelming you with "sea of red" exceptions, but is inconvenient because it basically disables advanced scripting. | ||
Using this switch turns this "nice by default" feature off and enables you to catch exceptions with your own try/catch. | ||
.NOTES | ||
Tags: Formatting | ||
Author: Simone Bizzotto | ||
Website: https://dbatools.io | ||
Copyright: (c) 2018 by dbatools, licensed under MIT | ||
License: MIT https://opensource.org/licenses/MIT | ||
.LINK | ||
https://dbatools.io/Invoke-DbatoolsFormatter | ||
.EXAMPLE | ||
PS C:\> Invoke-DbatoolsFormatter -Path C:\dbatools\functions\Get-DbaDatabase.ps1 | ||
Reformats C:\dbatools\functions\Get-DbaDatabase.ps1 to dbatools' standards | ||
#> | ||
[CmdletBinding()] | ||
param ( | ||
[parameter(Mandatory, ValueFromPipeline)] | ||
[object[]]$Path, | ||
[switch]$EnableException | ||
) | ||
begin { | ||
$HasInvokeFormatter = $null -ne (Get-Command Invoke-Formatter -ErrorAction SilentlyContinue).Version | ||
if (!($HasInvokeFormatter)) { | ||
Stop-Function -Message "You need a recent version of PSScriptAnalyzer installed" | ||
} | ||
$CBHRex = [regex]'(?smi)\s+<#[^#]*#>' | ||
$CBHStartRex = [regex]'(?<spaces>[ ]+)<#' | ||
$CBHEndRex = [regex]'(?<spaces>[ ]*)#>' | ||
} | ||
process { | ||
foreach ($p in $Path) { | ||
try { | ||
$realPath = (Resolve-Path -Path $p -ErrorAction Stop).Path | ||
} catch { | ||
Stop-Function -Message "Cannot find or resolve $p" -Continue | ||
} | ||
|
||
$content = Get-Content -Path $realPath -Raw -Encoding UTF8 | ||
#strip ending empty lines | ||
$content = $content -replace "(?s)`r`n\s*$" | ||
try { | ||
$content = Invoke-Formatter -ScriptDefinition $content -Settings CodeFormattingOTBS -ErrorAction Stop | ||
} catch { | ||
Write-Message -Level Warning "Unable to format $p" | ||
} | ||
#match the ending indentation of CBH with the starting one, see #4373 | ||
$CBH = $CBHRex.Match($content).Value | ||
if ($CBH) { | ||
#get starting spaces | ||
$startSpaces = $CBHStartRex.Match($CBH).Groups['spaces'] | ||
if ($startSpaces) { | ||
#get end | ||
$newCBH = $CBHEndRex.Replace($CBH, "$startSpaces#>") | ||
if ($newCBH) { | ||
#replace the CBH | ||
$content = $content.Replace($CBH, $newCBH) | ||
} | ||
} | ||
} | ||
$Utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $False | ||
$realContent = @() | ||
#trim whitespace lines | ||
foreach ($line in $content.Split("`n")) { | ||
$realContent += $line.TrimEnd() | ||
} | ||
[System.IO.File]::WriteAllText($realPath, ($realContent -Join "`r`n"), $Utf8NoBomEncoding) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,4 +30,4 @@ class Annotation { | |
$this.Description = $Json.description | ||
$this.Time = $Json.time | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.