11function Get-Turtle {
22 <#
3+ . SYNOPSIS
4+ Gets Turtle in PowerShell
5+ . DESCRIPTION
6+ Gets, sets, and moves a turtle object in PowerShell.
7+ . NOTES
8+ Each argument can be the name of a member of the turtle object.
9+
10+ After a member name is encountered, subsequent arguments will be passed to the member as parameters.
311 . EXAMPLE
412 turtle square 50
513 . EXAMPLE
@@ -8,6 +16,7 @@ function Get-Turtle {
816 turtle polygon 10 6
917 . EXAMPLE
1018 turtle ('forward', 10, 'rotate', 120 * 3)
19+
1120 #>
1221 [CmdletBinding (PositionalBinding = $false )]
1322 [Alias (' turtle' )]
@@ -79,6 +88,7 @@ function Get-Turtle {
7988 # We want to keep track of the current member,
8089 # and continue to the next word until we find a member name.
8190 $currentMember = $null
91+ $outputTurtle = $false
8292
8393 # To do this in one pass, we will iterate through the words and arguments.
8494 # We use an indexed loop so we can skip past claimed arguments.
@@ -159,12 +169,21 @@ function Get-Turtle {
159169 # Luckily, this should be one of the few cases where this does not annoy too much.
160170 # Properties being returned will largely be strings or numbers.
161171 if (-not ($stepOutput.pstypenames -eq ' Turtle' )) {
162- $stepOutput
172+ # Output the step
173+ $stepOutput
174+ # and set the output turtle to false.
175+ $outputTurtle = $false
163176 } else {
177+ # Set the current turtle to the step output.
164178 $currentTurtle = $stepOutput
179+ # and output it later (presumably).
180+ $outputTurtle = $true
165181 }
166182 }
167-
168- return $currentTurtle
183+
184+ # If the last members returned a turtle object, we can output it.
185+ if ($outputTurtle ) {
186+ return $currentTurtle
187+ }
169188 }
170189}
0 commit comments