Skip to content

Commit 431ad3a

Browse files
StartAutomatingStartAutomating
authored andcommitted
.AsSentence: Fixing Singleton mapping (Fixes #279)
1 parent c6de082 commit 431ad3a

1 file changed

Lines changed: 31 additions & 7 deletions

File tree

PipeScript.types.ps1xml

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -349,9 +349,10 @@ if ($IsRightToLeft) {
349349
}
350350

351351

352-
if ($SpecificCommands) {
353-
$potentialCommandNames = $specificCommandNames
352+
$sentences = @()
353+
if ($SpecificCommands) {
354354
$potentialCommands = $SpecificCommands
355+
$potentialCommandNames = @($SpecificCommands | Select-Object -ExpandProperty Name)
355356
} else {
356357

357358
# The first command element should be the name of the command.
@@ -611,7 +612,24 @@ foreach ($potentialCommand in $potentialCommands) {
611612
$commandElementIndex--
612613
continue
613614
}
614-
615+
elseif ($currentParameter) {
616+
if ($mappedParameters.Contains($currentParameter) -and
617+
$currentParameter.ParameterType -isnot [Collections.IList] -and
618+
$currentParameter.ParameterType -isnot [PSObject]
619+
) {
620+
$clauses += [PSCustomObject][Ordered]@{
621+
PSTypeName = 'PipeScript.Sentence.Clause'
622+
Name = if ($currentParameter) { $currentParameter} else { '' }
623+
ParameterName = if ($currentParameterMetadata) { $currentParameterMetadata.Name } else { '' }
624+
Words = $currentClause
625+
}
626+
$currentParameter = $null
627+
$currentParameterMetadata = $null
628+
$currentClause = @()
629+
$commandElementIndex--
630+
continue
631+
}
632+
}
615633

616634
# Refersh our $commandElement, as the index may have changed.
617635
$commandElement = $CommandElements[$commandElementIndex]
@@ -626,7 +644,10 @@ foreach ($potentialCommand in $potentialCommands) {
626644

627645
# If we have a current parameter
628646
if ($currentParameter) {
647+
629648
# Map the current element to this parameter.
649+
650+
630651
$mappedParameters[$currentParameter] =
631652
if ($mappedParameters[$currentParameter]) {
632653
@($mappedParameters[$currentParameter]) + @($commandElement)
@@ -642,6 +663,8 @@ foreach ($potentialCommand in $potentialCommands) {
642663
}
643664
}
644665
$currentClause += $commandElement
666+
667+
645668
} else {
646669
# otherwise add the command element to our unbound parameters.
647670
$unboundParameters +=
@@ -665,9 +688,11 @@ foreach ($potentialCommand in $potentialCommands) {
665688
Name = if ($currentParameter) { $currentParameter} else { '' }
666689
ParameterName = if ($currentParameterMetadata) { $currentParameterMetadata.Name } else { '' }
667690
Words = $currentClause
668-
}
691+
}
669692
}
670693

694+
695+
671696
if ($potentialCommand -isnot [Management.Automation.ApplicationInfo] -and
672697
@($mappedParameters.Keys) -match '^[-/]') {
673698
$keyIndex = -1
@@ -698,9 +723,8 @@ foreach ($potentialCommand in $potentialCommands) {
698723
Parameters = $mappedParameters
699724
Arguments = $unboundParameters
700725
}
701-
702-
$sentence
703-
726+
$sentences+= $sentence
727+
$sentence
704728
}
705729
</Script>
706730
</ScriptMethod>

0 commit comments

Comments
 (0)