Skip to content

Commit

Permalink
so that we use join path Use Join-path to improve cross plat #934
Browse files Browse the repository at this point in the history
  • Loading branch information
SQLDBAWithABeard committed Apr 5, 2023
1 parent b7fa967 commit ea3618c
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions source/internal/functions/New-Json.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ function New-Json {
$repos = Get-CheckRepo
$collection = $groups = $repofiles = @()
foreach ($repo in $repos) {
$repofiles += (Get-ChildItem "$repo\*.Tests.ps1")
$folders = Join-Path -Path $repo -ChildPath '*.Tests.ps1'
$repofiles += (Get-ChildItem $folders )
}
$tokens = $null
$errors = $null
Expand Down Expand Up @@ -102,31 +103,25 @@ function New-Json {
# CHoose the type
if ($Describe.Parent -match "Get-Instance") {
$type = "Sqlinstance"
}
elseif ($Describe.Parent -match "Get-ComputerName" -or $Describe.Parent -match "AllServerInfo") {
} elseif ($Describe.Parent -match "Get-ComputerName" -or $Describe.Parent -match "AllServerInfo") {
$type = "ComputerName"
}
elseif ($Describe.Parent -match "Get-ClusterObject") {
} elseif ($Describe.Parent -match "Get-ClusterObject") {
$Type = "ClusterNode"
}
else {
} else {
#Choose the type from the new way from inside the foreach
if ($ComputerNameForEach -match $title) {
$type = "ComputerName"
}
elseif ($InstanceNameForEach -match $title) {
} elseif ($InstanceNameForEach -match $title) {
$type = "Sqlinstance"
}
else {
} else {
$type = $null
}
}

if ($filename -eq 'HADR') {
## HADR configs are outside of describe
$configs = [regex]::matches($check, "Get-DbcConfigValue\s([a-zA-Z\d]*.[a-zA-Z\d]*.[a-zA-Z\d]*.[a-zA-Z\d]*\b)").groups.Where{ $_.Name -eq 1 }.Value
}
else {
} else {
$configs = [regex]::matches($describe.Parent.Extent.Text, "Get-DbcConfigValue\s([a-zA-Z\d]*.[a-zA-Z\d]*.[a-zA-Z\d]*.[a-zA-Z\d]*\b)").groups.Where{ $_.Name -eq 1 }.Value
}
$Config = ''
Expand Down Expand Up @@ -202,18 +197,19 @@ function New-Json {
}
}
$singletags = (($collection.AllTags -split ",").Trim() | Group-Object | Where-Object { $_.Count -eq 1 -and $_.Name -notin $groups })
$Descriptions = Get-Content $script:ModuleRoot\internal\configurations\DbcCheckDescriptions.json -Raw | ConvertFrom-Json
$descriptionsFile = Join-Path -Path $script:ModuleRoot -ChildPath 'internal\configurations\DbcCheckDescriptions.json'
$descriptions = [System.IO.File]::ReadAllText($descriptionsFile) | ConvertFrom-Json
foreach ($check in $collection) {
$unique = $singletags | Where-Object { $_.Name -in ($check.AllTags -split ",").Trim() }
$check.UniqueTag = $unique.Name
$Check.Description = $Descriptions.Where{ $_.UniqueTag -eq $Check.UniqueTag }.Description
}
try {
if ($PSCmdlet.ShouldProcess("$script:localapp\checks.json" , "Convert Json and write to file")) {
ConvertTo-Json -InputObject $collection | Out-File "$script:localapp\checks.json"
$checksfile = Join-Path -Path $script:localapp -ChildPath 'checks.json'
if ($PSCmdlet.ShouldProcess($checksfile , "Convert Json and write to file")) {
ConvertTo-Json -InputObject $collection | Out-File $checksfile
}
}
catch {
} catch {
Write-PSFMessage "Failed to create the json, something weird might happen now with tags and things" -Level Significant
}

Expand Down

0 comments on commit ea3618c

Please sign in to comment.