1
1
function Get-Turtle {
2
2
<#
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.
3
11
. EXAMPLE
4
12
turtle square 50
5
13
. EXAMPLE
@@ -8,6 +16,7 @@ function Get-Turtle {
8
16
turtle polygon 10 6
9
17
. EXAMPLE
10
18
turtle ('forward', 10, 'rotate', 120 * 3)
19
+
11
20
#>
12
21
[CmdletBinding (PositionalBinding = $false )]
13
22
[Alias (' turtle' )]
@@ -79,6 +88,7 @@ function Get-Turtle {
79
88
# We want to keep track of the current member,
80
89
# and continue to the next word until we find a member name.
81
90
$currentMember = $null
91
+ $outputTurtle = $false
82
92
83
93
# To do this in one pass, we will iterate through the words and arguments.
84
94
# We use an indexed loop so we can skip past claimed arguments.
@@ -159,12 +169,21 @@ function Get-Turtle {
159
169
# Luckily, this should be one of the few cases where this does not annoy too much.
160
170
# Properties being returned will largely be strings or numbers.
161
171
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
163
176
} else {
177
+ # Set the current turtle to the step output.
164
178
$currentTurtle = $stepOutput
179
+ # and output it later (presumably).
180
+ $outputTurtle = $true
165
181
}
166
182
}
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
+ }
169
188
}
170
189
}
0 commit comments