Skip to content

Commit ecac70f

Browse files
author
James Brundage
committed
feat: Save-Turtle ( Fixes #52 )
Autoselecting properties based off of extension.
1 parent eecd96a commit ecac70f

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

Commands/Save-Turtle.ps1

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ function Save-Turtle {
66
Saves a turtle graphics pattern to a file.
77
.EXAMPLE
88
New-Turtle |
9-
Move-Turtle Si
9+
Move-Turtle SierpinskiTriangle 20 3 |
10+
Save-Turtle "./SierpinskiTriangle.svg"
11+
.EXAMPLE
12+
Move-Turtle BoxFractal 15 5 |
13+
Set-Turtle Stroke '#4488ff' |
14+
Save-Turtle ./BoxFractal.png
1015
#>
1116
param(
1217
# The file path to save the turtle graphics pattern.
@@ -17,12 +22,7 @@ function Save-Turtle {
1722

1823
# The property of the turtle to save.
1924
[ArgumentCompleter({
20-
param ( $commandName,
21-
$parameterName,
22-
$wordToComplete,
23-
$commandAst,
24-
$fakeBoundParameters )
25-
$myInv = $myInvocation
25+
param ( $commandName, $parameterName, $wordToComplete, $commandAst, $fakeBoundParameters )
2626
$turtleType = Get-TypeData -TypeName Turtle
2727
$propertyNames = @(foreach ($memberName in $turtleType.Members.Keys) {
2828
if ($turtleType.Members[$memberName] -is [System.Management.Automation.Runspaces.ScriptPropertyData]) {
@@ -48,6 +48,11 @@ function Save-Turtle {
4848

4949
process {
5050
if (-not $inputObject) { return }
51+
switch -regex ($FilePath) {
52+
'\.png$' { if ($Property -eq 'Symbol') { $Property = 'PNG' } }
53+
'\.jpe?g$' { if ($Property -eq 'Symbol') { $Property = 'JPEG' } }
54+
'\.webp$' { if ($Property -eq 'Symbol') { $Property = 'WEBP' } }
55+
}
5156
$toExport = $inputObject.$Property
5257
if (-not $toExport) { return }
5358
$unresolvedPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($FilePath)
@@ -60,6 +65,7 @@ function Save-Turtle {
6065
} else {
6166
$toExport > $unresolvedPath
6267
}
68+
6369
if ($?) {
6470
Get-Item -Path $unresolvedPath
6571
}

0 commit comments

Comments
 (0)