Update what-is.ps1

This commit is contained in:
Markus Fleschutz
2022-12-21 08:14:30 +01:00
parent 3f5188ceb9
commit 9b32339079
2 changed files with 15 additions and 20 deletions

View File

@ -2,9 +2,9 @@
.SYNOPSIS
Prints a description of an abbreviation
.DESCRIPTION
This PowerShell script prints a description of the given abbreviation.
.PARAMETER abbreviation
Specifies the appreviation to look for
This PowerShell script queries and prints a description of the given abbreviation.
.PARAMETER abbr
Specifies the abbreviation to look for
.EXAMPLE
PS> ./what-is IAS
.LINK
@ -13,32 +13,26 @@
Author: Markus Fleschutz | License: CC0
#>
param([string]$abbreviation = "")
function Reply { param([string]$Text)
& "$PSScriptRoot/speak-english.ps1" "$Text"
}
param([string]$abbr = "")
try {
if ($abbreviation -eq "" ) { $abbreviation = read-host "Enter the abbreviation" }
$FoundOne = $false
$Files = (get-childItem "$PSScriptRoot/../Data/Abbr/*.csv")
if ($abbr -eq "" ) { $abbr = Read-Host "Enter the abbreviation" }
$Missing = $true
$Files = (Get-ChildItem "$PSScriptRoot/../Data/Abbr/*.csv")
foreach ($File in $Files) {
$Table = import-csv "$File"
$Table = Import-CSV "$File"
foreach($Row in $Table) {
if ($Row.Abbr -eq $abbreviation) {
$Basename = (get-item "$File").Basename
Reply "In $Basename $($Row.Abbr) may refer to $($Row.Term)"
$FoundOne = $true
if ($Row.Abbr -eq $abbr) {
$Basename = (Get-Item "$File").Basename
"🔎 In $Basename $($Row.Abbr) may refer to $($Row.Term)"
$Missing = $false
}
}
}
if ($FoundOne -eq $false) { Reply "Sorry, no database entry found." }
if ($Missing) { "Sorry, '$abbr' is missing in the database." }
exit 0 # success
} catch {
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
exit 1
}
}