Skip to content

Commit

Permalink
Fixes cmd aliases not evaluated on plugin run
Browse files Browse the repository at this point in the history
  • Loading branch information
LordHepipud committed Dec 19, 2022
1 parent 69ced2f commit 2341085
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
3 changes: 2 additions & 1 deletion doc/100-General/10-Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ documentation before upgrading to a new release.

Released closed milestones can be found on [GitHub](https://github.com/Icinga/icinga-powershell-framework/milestones?state=closed).

## 1.10.1 (2022-27-10)
## 1.10.1 (2022-12-20)

[Issue and PRs](https://github.com/Icinga/icinga-powershell-framework/milestone/27?closed=1)

### Bugfixes

* [#582](https://github.com/Icinga/icinga-powershell-framework/issues/582) Fixes background service registration caused by migration task for v1.10.0 being executed even when no services were defined before
* [#588](https://github.com/Icinga/icinga-powershell-framework/issues/588) Fixes threshold values causing an error because of too aggressive regex expression
* [#599](https://github.com/Icinga/icinga-powershell-plugins/issues/599) Fixes plugin argument parser to proceed with real argument names and possible provided aliases

## 1.10.0 (2022-08-30)

Expand Down
24 changes: 19 additions & 5 deletions lib/core/tools/ConvertTo-IcingaPowerShellArguments.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,27 @@ function ConvertTo-IcingaPowerShellArguments()
return @{ };
}

$CommandHelp = Get-Help -Name $Command -Full -ErrorAction SilentlyContinue;
$CmdData = Get-Command $Command -ErrorAction SilentlyContinue;
[array]$CmdAllowedArgs = $CmdData.Parameters.Keys;

# Ensure we do not cause exceptions along the border in case the plugin is not installed
if ($null -eq $CommandHelp) {
if ($null -eq $CmdAllowedArgs) {
return @{ };
}

# Ensure we not only add the parameter name to our allow list but also possible aliases
foreach ($entry in $CmdData.Parameters.Keys) {
if ($CmdData.Parameters[$entry].Aliases.Count -eq 0) {
continue;
}

foreach ($cmdAlias in $CmdData.Parameters[$entry].Aliases) {
if ($CmdAllowedArgs -NotContains $cmdAlias) {
$CmdAllowedArgs += $cmdAlias;
}
}
}

[hashtable]$IcingaArguments = @{ };
[int]$ArgumentIndex = 0;

Expand All @@ -50,7 +64,7 @@ function ConvertTo-IcingaPowerShellArguments()
}

# Check if our string value is a argument contained inside the command being executed
if ($CommandHelp.parameters.parameter.name -Contains ($Arguments[$ArgumentIndex].SubString(1, $Arguments[$ArgumentIndex].Length - 1)) -eq $FALSE) {
if ($CmdAllowedArgs -Contains ($Arguments[$ArgumentIndex].SubString(1, $Arguments[$ArgumentIndex].Length - 1)) -eq $FALSE) {
# Continue if we are not an argument
$ArgumentIndex += 1;
continue;
Expand All @@ -77,7 +91,7 @@ function ConvertTo-IcingaPowerShellArguments()

# If our next value on the index is an argument in our command
# -> The current argument seems to be a switch argument
if ($CommandHelp.parameters.parameter.name -Contains ($NextValue.SubString(1, $NextValue.Length - 1))) {
if ($CmdAllowedArgs -Contains ($NextValue.SubString(1, $NextValue.Length - 1))) {
if ($IcingaArguments.ContainsKey($Argument) -eq $FALSE) {
$IcingaArguments.Add($Argument, $TRUE);
}
Expand All @@ -103,7 +117,7 @@ function ConvertTo-IcingaPowerShellArguments()
[string]$NextValue = $Arguments[$ReadStringIndex + 1];

# Check the next string element and evaluate if it is an argument for our command
if ($CommandHelp.parameters.parameter.name -Contains ($NextValue.SubString(1, $NextValue.Length - 1))) {
if ($CmdAllowedArgs -Contains ($NextValue.SubString(1, $NextValue.Length - 1))) {
break;
}

Expand Down

0 comments on commit 2341085

Please sign in to comment.