icinga-powershell-framework/lib/core/installer/tools/Write-IcingaManagementConsoleCommand.psm1

38 lines
1.4 KiB
PowerShell
Raw Normal View History

function Write-IcingaManagementConsoleCommand()
{
param (
$Entry = $null,
$Values = @()
);
2021-09-02 07:44:17 -04:00
if ($null -eq $Entry -Or $Entry.ContainsKey('Action') -eq $FALSE) {
return '';
}
2021-09-02 07:44:17 -04:00
[string]$PrintArguments = '';
[string]$PrintCommand = '';
[hashtable]$DefinedArgs = @{ };
if ($entry.Action.ContainsKey('Arguments') -And $entry.Action.Arguments.ContainsKey('-Command')) {
$PrintCommand = $Entry.Action.Arguments['-Command'];
if ($Entry.Action.Arguments.ContainsKey('-CmdArguments')) {
$DefinedArgs = $Entry.Action.Arguments['-CmdArguments'];
}
} elseif ($entry.Action.ContainsKey('Command')) {
$PrintCommand = $entry.Action.Command;
if ($Entry.Action.ContainsKey('Arguments')) {
$DefinedArgs = $Entry.Action.Arguments;
}
}
$PrintArguments = ConvertTo-IcingaCommandArgumentString -Command $PrintCommand -CommandArguments $DefinedArgs;
2021-09-02 07:44:17 -04:00
$PrintArguments = $PrintArguments.Replace('$DefaultValues$', ((ConvertFrom-IcingaArrayToString -Array $Values -AddQuotes)));
2021-09-02 07:44:17 -04:00
if ([string]::IsNullOrEmpty($PrintArguments) -eq $FALSE) {
$PrintArguments = [string]::Format(' {0}', $PrintArguments);
}
2021-09-02 07:44:17 -04:00
Write-IcingaConsolePlain ([string]::Format('PS> {0}{1};', $PrintCommand, $PrintArguments)) -ForeColor Magenta;
Write-IcingaConsolePlain '';
}