Update what-is.ps1

This commit is contained in:
Markus Fleschutz 2021-11-28 11:57:49 +01:00
parent 0b34ace6fd
commit 92cfac922f
2 changed files with 9 additions and 6 deletions

Binary file not shown.

View File

@ -6,7 +6,7 @@
.PARAMETER abbreviation .PARAMETER abbreviation
Specifies the appreviation to look for Specifies the appreviation to look for
.EXAMPLE .EXAMPLE
PS> ./what-is CIA PS> ./what-is IAS
.NOTES .NOTES
Author: Markus Fleschutz · License: CC0 Author: Markus Fleschutz · License: CC0
.LINK .LINK
@ -15,26 +15,29 @@
param([string]$abbreviation = "") param([string]$abbreviation = "")
function Reply { param([string]$Text)
"$Text"
& "$PSScriptRoot/speak-english.ps1" "$Text"
}
try { try {
if ($abbreviation -eq "" ) { $abbreviation = read-host "Enter the abbreviation" } if ($abbreviation -eq "" ) { $abbreviation = read-host "Enter the abbreviation" }
write-progress "Searching ..."
$FoundOne = $false $FoundOne = $false
$Files = (get-childItem "$PSScriptRoot/../Data/Abbr/*" -attributes !Directory) $Files = (get-childItem "$PSScriptRoot/../Data/Abbr/*.csv")
foreach ($File in $Files) { foreach ($File in $Files) {
$Table = import-csv "$File" $Table = import-csv "$File"
foreach($Row in $Table) { foreach($Row in $Table) {
if ($Row.Abbreviation -eq $abbreviation) { if ($Row.Abbreviation -eq $abbreviation) {
$Basename = (get-item "$File").Basename $Basename = (get-item "$File").Basename
"$($Row.Abbreviation) = $($Row.Definition) in $Basename" Reply "$($Row.Definition) ($($Row.Abbreviation)) in $Basename."
$FoundOne = $true $FoundOne = $true
} }
} }
} }
if ($FoundOne -eq $false) { "Sorry, no entry for $abbreviation found" } if ($FoundOne -eq $false) { Reply "Sorry, no entry found" }
exit 0 # success exit 0 # success
} catch { } catch {
"⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))" "⚠️ Error: $($Error[0]) ($($MyInvocation.MyCommand.Name):$($_.InvocationInfo.ScriptLineNumber))"