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

@ -306,6 +306,7 @@ RJAF,Royal Jordanian Air Force
RJC,Reject RJC,Reject
RPI,Runway Point of Intercept RPI,Runway Point of Intercept
RPM,Rotations per Minute RPM,Rotations per Minute
ROFZ,Runway Obstacle Free Zone
RMI,Radio Magnetic Indicator RMI,Radio Magnetic Indicator
RNAV,Area Navigation RNAV,Area Navigation
RNP,Required Navigation Performance RNP,Required Navigation Performance

Can't render this file because it has a wrong number of fields in line 123.

View File

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