Skip to content

Commit 2341085

Browse files
committed
Fixes cmd aliases not evaluated on plugin run
1 parent 69ced2f commit 2341085

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

doc/100-General/10-Changelog.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,15 @@ documentation before upgrading to a new release.
77

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

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

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

1414
### Bugfixes
1515

1616
* [#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
1717
* [#588](https://github.com/Icinga/icinga-powershell-framework/issues/588) Fixes threshold values causing an error because of too aggressive regex expression
18+
* [#599](https://github.com/Icinga/icinga-powershell-plugins/issues/599) Fixes plugin argument parser to proceed with real argument names and possible provided aliases
1819

1920
## 1.10.0 (2022-08-30)
2021

lib/core/tools/ConvertTo-IcingaPowerShellArguments.psm1

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,27 @@ function ConvertTo-IcingaPowerShellArguments()
2525
return @{ };
2626
}
2727

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

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

36+
# Ensure we not only add the parameter name to our allow list but also possible aliases
37+
foreach ($entry in $CmdData.Parameters.Keys) {
38+
if ($CmdData.Parameters[$entry].Aliases.Count -eq 0) {
39+
continue;
40+
}
41+
42+
foreach ($cmdAlias in $CmdData.Parameters[$entry].Aliases) {
43+
if ($CmdAllowedArgs -NotContains $cmdAlias) {
44+
$CmdAllowedArgs += $cmdAlias;
45+
}
46+
}
47+
}
48+
3549
[hashtable]$IcingaArguments = @{ };
3650
[int]$ArgumentIndex = 0;
3751

@@ -50,7 +64,7 @@ function ConvertTo-IcingaPowerShellArguments()
5064
}
5165

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

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

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

0 commit comments

Comments
 (0)