Skip to content

Commit c6de082

Browse files
author
James Brundage
committed
.AsSentence: Fixing Singleton mapping (Fixes #279)
1 parent 0d8a12d commit c6de082

1 file changed

Lines changed: 31 additions & 7 deletions

File tree

Types/CommandAST/AsSentence.ps1

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

6969

70-
if ($SpecificCommands) {
71-
$potentialCommandNames = $specificCommandNames
70+
$sentences = @()
71+
if ($SpecificCommands) {
7272
$potentialCommands = $SpecificCommands
73+
$potentialCommandNames = @($SpecificCommands | Select-Object -ExpandProperty Name)
7374
} else {
7475

7576
# The first command element should be the name of the command.
@@ -329,7 +330,24 @@ foreach ($potentialCommand in $potentialCommands) {
329330
$commandElementIndex--
330331
continue
331332
}
332-
333+
elseif ($currentParameter) {
334+
if ($mappedParameters.Contains($currentParameter) -and
335+
$currentParameter.ParameterType -isnot [Collections.IList] -and
336+
$currentParameter.ParameterType -isnot [PSObject]
337+
) {
338+
$clauses += [PSCustomObject][Ordered]@{
339+
PSTypeName = 'PipeScript.Sentence.Clause'
340+
Name = if ($currentParameter) { $currentParameter} else { '' }
341+
ParameterName = if ($currentParameterMetadata) { $currentParameterMetadata.Name } else { '' }
342+
Words = $currentClause
343+
}
344+
$currentParameter = $null
345+
$currentParameterMetadata = $null
346+
$currentClause = @()
347+
$commandElementIndex--
348+
continue
349+
}
350+
}
333351

334352
# Refersh our $commandElement, as the index may have changed.
335353
$commandElement = $CommandElements[$commandElementIndex]
@@ -344,7 +362,10 @@ foreach ($potentialCommand in $potentialCommands) {
344362

345363
# If we have a current parameter
346364
if ($currentParameter) {
365+
347366
# Map the current element to this parameter.
367+
368+
348369
$mappedParameters[$currentParameter] =
349370
if ($mappedParameters[$currentParameter]) {
350371
@($mappedParameters[$currentParameter]) + @($commandElement)
@@ -360,6 +381,8 @@ foreach ($potentialCommand in $potentialCommands) {
360381
}
361382
}
362383
$currentClause += $commandElement
384+
385+
363386
} else {
364387
# otherwise add the command element to our unbound parameters.
365388
$unboundParameters +=
@@ -383,9 +406,11 @@ foreach ($potentialCommand in $potentialCommands) {
383406
Name = if ($currentParameter) { $currentParameter} else { '' }
384407
ParameterName = if ($currentParameterMetadata) { $currentParameterMetadata.Name } else { '' }
385408
Words = $currentClause
386-
}
409+
}
387410
}
388411

412+
413+
389414
if ($potentialCommand -isnot [Management.Automation.ApplicationInfo] -and
390415
@($mappedParameters.Keys) -match '^[-/]') {
391416
$keyIndex = -1
@@ -416,7 +441,6 @@ foreach ($potentialCommand in $potentialCommands) {
416441
Parameters = $mappedParameters
417442
Arguments = $unboundParameters
418443
}
419-
420-
$sentence
421-
444+
$sentences+= $sentence
445+
$sentence
422446
}

0 commit comments

Comments
 (0)