2021-08-19 11:19:26 -04:00
|
|
|
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-08-19 11:19:26 -04:00
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-27 14:59:55 -05:00
|
|
|
$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-08-19 11:19:26 -04:00
|
|
|
|
2021-09-02 07:44:17 -04:00
|
|
|
if ([string]::IsNullOrEmpty($PrintArguments) -eq $FALSE) {
|
|
|
|
|
$PrintArguments = [string]::Format(' {0}', $PrintArguments);
|
2021-08-19 11:19:26 -04:00
|
|
|
}
|
2021-09-02 07:44:17 -04:00
|
|
|
|
|
|
|
|
Write-IcingaConsolePlain ([string]::Format('PS> {0}{1};', $PrintCommand, $PrintArguments)) -ForeColor Magenta;
|
|
|
|
|
Write-IcingaConsolePlain '';
|
2021-08-19 11:19:26 -04:00
|
|
|
}
|