From 9f69bedb52efddd664c798687394b6996c0745d9 Mon Sep 17 00:00:00 2001 From: Lord Hepipud Date: Mon, 3 Aug 2020 12:29:28 +0200 Subject: [PATCH] Adds dynamic copyright loading and adds header to main shell Extends #87 --- icinga-powershell-framework.psm1 | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/icinga-powershell-framework.psm1 b/icinga-powershell-framework.psm1 index 311b682..2b1dee3 100644 --- a/icinga-powershell-framework.psm1 +++ b/icinga-powershell-framework.psm1 @@ -269,10 +269,23 @@ function Invoke-IcingaCommand() [switch]$SkipHeader = $FALSE ); + Import-LocalizedData ` + -BaseDirectory $PSScriptRoot ` + -FileName 'icinga-powershell-framework.psd1' ` + -BindingVariable IcingaFrameworkData; + + # Print a header informing our user that loaded the Icinga Framework with a specific + # version. We can also skip the header by using $SKipHeader + if ($SkipHeader -eq $FALSE) { + Write-Host '******************************************************'; + Write-Host ([string]::Format('** Icinga PowerShell Framework {0}', $IcingaFrameworkData.PrivateData.Version)); + Write-Host ([string]::Format('** Copyright {0}', $IcingaFrameworkData.Copyright)); + Write-Host '******************************************************'; + } + powershell.exe -NoExit -Command { - $Script = $args[0]; - [bool]$Header = $args[1].IsPresent; - $RootPath = $args[2]; + $Script = $args[0]; + $RootPath = $args[1]; # Load our Icinga Framework Use-Icinga; @@ -287,23 +300,13 @@ function Invoke-IcingaCommand() exit $LASTEXITCODE; } - # Print a header informing our user that loaded the Icinga Framework with a specific - # version. We can also skip the header by using $SKipHeader - if ($null -eq $Header -Or $Header -eq $FALSE -Or -Not $Header) { - $FrameworkVersion = Get-IcingaPowerShellModuleVersion 'icinga-powershell-framework'; - Write-IcingaConsolePlain '******************************************************'; - Write-IcingaConsolePlain '** Icinga PowerShell Framework {0}' -Objects $FrameworkVersion; - Write-IcingaConsolePlain '** Copyright (c) 2020 Icinga GmbH | MIT'; - Write-IcingaConsolePlain '******************************************************'; - } - # Set our "path" to something different so we know that we loaded the Framework function prompt { Write-Host -Object "icinga" -NoNewline; return "> " } - } -Args $ScriptBlock, $SkipHeader, $PSScriptRoot; + } -Args $ScriptBlock, $PSScriptRoot; } Set-Alias icinga Invoke-IcingaCommand -Description "Execute Icinga Framework commands in a new PowerShell instance for testing or quick access to data";