@@ -390,6 +390,10 @@ if ($SpecificCommands) {
390390
391391$mappedParameters = [Ordered]@{}
392392
393+ if (-not $Script:SentenceWordCache) {
394+ $Script:SentenceWordCache = @{}
395+ }
396+
393397$potentialCommandIndex = -1
394398foreach ($potentialCommand in $potentialCommands) {
395399 $potentialCommandIndex++
@@ -516,8 +520,18 @@ foreach ($potentialCommand in $potentialCommands) {
516520 # We need to know the name of the parameter as it was written.
517521 # However, we also want to allow --parameters and /parameters,
518522 $potentialParameterName = $barewordSequenece[0]
519- $barewordSequenece = $barewordSequenece -join ' ' -replace '[-/]'
520523 # therefore, we will compare against the potential name without leading dashes or slashes.
524+
525+ $potentialBarewordList =@(
526+ for (
527+ $barewordSequenceIndex = $barewordSequenece.Length;
528+ $barewordSequenceIndex -ge 0;
529+ $barewordSequenceIndex--
530+ ) {
531+ $barewordSequenece[0..$barewordSequenceIndex] -join ' ' -replace '^[-/]{0,}'
532+ }
533+ )
534+
521535 $dashAndSlashlessName = $potentialParameterName -replace '^[-/]{0,}'
522536
523537 # If no parameter was found but a parameter has ValueFromRemainingArguments, we will map to that.
@@ -527,19 +541,15 @@ foreach ($potentialCommand in $potentialCommands) {
527541 foreach ($potentialParameter in $potentialParameters.Values) {
528542 $parameterFound = $(
529543 # If the parameter name matches,
530- if ($potentialParameter.Name -eq $dashAndSlashlessName ) {
544+ if ($potentialBarewordList -contains $potentialParameter.Name ) {
531545 $true # we've found it,
532546 } else {
533547 # otherwise, we have to check each alias.
534- foreach ($potentialAlias in $potentialParameter.Aliases) {
535- if ($barewordSequenece -match '\s' -and
536- $potentialAlias -eq $barewordSequenece) {
537- $potentialParameterName = $barewordSequenece
548+ :nextAlias foreach ($potentialAlias in $potentialParameter.Aliases) {
549+ if ($potentialBarewordList -contains $potentialAlias) {
550+ $potentialParameterName = $potentialAlias
538551 $true
539552 break
540- } elseif ($potentialAlias -eq $dashAndSlashlessName) {
541- $true
542- break
543553 }
544554 }
545555 }
0 commit comments