Update what-is.ps1

This commit is contained in:
Markus Fleschutz 2023-03-28 11:24:49 +02:00
parent 221c8f7f9e
commit c2b4b23d75

View File

@ -1,8 +1,8 @@
<# <#
.SYNOPSIS .SYNOPSIS
Describes an abbreviation Explains an abbreviation
.DESCRIPTION .DESCRIPTION
This PowerShell script queries and prints a description of the given abbreviation. This PowerShell script queries the description of the given abbreviation and prints it.
.PARAMETER abbr .PARAMETER abbr
Specifies the abbreviation to look for Specifies the abbreviation to look for
.EXAMPLE .EXAMPLE
@ -18,19 +18,19 @@ param([string]$abbr = "")
try { try {
if ($abbr -eq "" ) { $abbr = Read-Host "Enter the abbreviation" } if ($abbr -eq "" ) { $abbr = Read-Host "Enter the abbreviation" }
$Missing = $true
$Files = (Get-ChildItem "$PSScriptRoot/../Data/Abbr/*.csv") $Files = (Get-ChildItem "$PSScriptRoot/../Data/Abbr/*.csv")
foreach ($File in $Files) { [int]$Matches = 0
foreach($File in $Files) {
$Table = Import-CSV "$File" $Table = Import-CSV "$File"
foreach($Row in $Table) { foreach($Row in $Table) {
if ($Row.ABBR -eq $abbr) { if ($Row.ABBR -eq $abbr) {
$Basename = (Get-Item "$File").Basename -Replace "_"," " $Basename = (Get-Item "$File").Basename -Replace "_"," "
"💡 In $Basename $($Row.ABBR) may refer to $($Row.TERM)." "💡 In $Basename $($Row.ABBR) may refer to: $($Row.TERM)"
$Missing = $false $Matches++
} }
} }
} }
if ($Missing) { "Sorry, '$abbr' is missing in the database." } if ($Matches -eq 0) { "Sorry, '$abbr' is missing in the database." }
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" "⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"