File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ function Save-Turtle {
2+ <#
3+ . SYNOPSIS
4+ Saves a turtle.
5+ . DESCRIPTION
6+ Saves a turtle graphics pattern to a file.
7+ . EXAMPLE
8+ New-Turtle |
9+ Move-Turtle Si
10+ #>
11+ param (
12+ # The file path to save the turtle graphics pattern.
13+ [Parameter (ValueFromPipelineByPropertyName )]
14+ [Alias (' Path' )]
15+ [string ]
16+ $FilePath ,
17+
18+ # The property of the turtle to save.
19+ [ArgumentCompleter ({
20+ param ( $commandName ,
21+ $parameterName ,
22+ $wordToComplete ,
23+ $commandAst ,
24+ $fakeBoundParameters )
25+ $myInv = $myInvocation
26+ $turtleType = Get-TypeData - TypeName Turtle
27+ $propertyNames = @ (foreach ($memberName in $turtleType.Members.Keys ) {
28+ if ($turtleType.Members [$memberName ] -is [System.Management.Automation.Runspaces.ScriptPropertyData ]) {
29+ $memberName
30+ }
31+ })
32+
33+ if ($wordToComplete ) {
34+ return $propertyNames -like " $wordToComplete *"
35+ } else {
36+ return $propertyNames
37+ }
38+ })]
39+ [string ]
40+ $Property = ' Symbol' ,
41+
42+ # The turtle input object.
43+ [Parameter (ValueFromPipeline )]
44+ [Alias (' Turtle' )]
45+ [PSObject ]
46+ $InputObject
47+ )
48+
49+ process {
50+ if (-not $inputObject ) { return }
51+ $toExport = $inputObject .$Property
52+ if (-not $toExport ) { return }
53+ $unresolvedPath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath ($FilePath )
54+ $null = New-Item - ItemType File - Force - Path $unresolvedPath
55+ if ($toExport -is [xml ]) {
56+ $toExport.Save (" $unresolvedPath " )
57+ }
58+ elseif ($toExport -is [byte []]) {
59+ Set-Content - Path $unresolvedPath - Value $toExport - AsByteStream
60+ } else {
61+ $toExport > $unresolvedPath
62+ }
63+ if ($? ) {
64+ Get-Item - Path $unresolvedPath
65+ }
66+ }
67+ }
You can’t perform that action at this time.
0 commit comments