|
| 1 | +This directory and it's subdirectories contain the Transpilers that ship with PipeScript. |
| 2 | + |
| 3 | +Transpilers should have the extension ```.psx.ps1``` |
| 4 | + |
| 5 | +Any other module can define it's own Transpilers. |
| 6 | + |
| 7 | +All the module needs to do for the transpilers to be recognized by PipeScript is add PipeScript to the ```.PrivateData.PSData.Tags``` section of the module's manifest file. |
| 8 | + |
| 9 | +This directory includes uncategorized or 'common' transpilers. |
| 10 | + |
| 11 | + |
| 12 | +|DisplayName |Synopsis | |
| 13 | +|----------------------------------------|---------------------------------------------------------------------| |
| 14 | +|[Decorate](Decorate.psx.ps1) |[decorate transpiler](Decorate.psx.ps1) | |
| 15 | +|[Explicit](Explicit.psx.ps1) |[Makes Output from a PowerShell function Explicit.](Explicit.psx.ps1)| |
| 16 | +|[Help](Help.psx.ps1) |[Help Transpiler](Help.psx.ps1) | |
| 17 | +|[Include](Include.psx.ps1) |[Includes Files](Include.psx.ps1) | |
| 18 | +|[Inherit](Inherit.psx.ps1) |[Inherits a Command](Inherit.psx.ps1) | |
| 19 | +|[OutputFile](OutputFile.psx.ps1) |[Outputs to a File](OutputFile.psx.ps1) | |
| 20 | +|[ProxyCommand](ProxyCommand.psx.ps1) |[Creates Proxy Commands](ProxyCommand.psx.ps1) | |
| 21 | +|[RenameVariable](RenameVariable.psx.ps1)|[Renames variables](RenameVariable.psx.ps1) | |
| 22 | +|[Rest](Rest.psx.ps1) |[Generates PowerShell to talk to a REST api.](Rest.psx.ps1) | |
| 23 | + |
| 24 | + |
| 25 | + |
| 26 | +### Examples |
| 27 | + |
| 28 | +#### Decorate Example 1 |
| 29 | + |
| 30 | + |
| 31 | +~~~PowerShell |
| 32 | + { |
| 33 | + $v = [PSCustomObject]@{} |
| 34 | + [decorate('MyTypeName',Clear,PassThru)]$v |
| 35 | + }.Transpile() |
| 36 | +~~~ |
| 37 | + |
| 38 | +#### Explicit Example 1 |
| 39 | + |
| 40 | + |
| 41 | +~~~PowerShell |
| 42 | + Invoke-PipeScript { |
| 43 | + [explicit()] |
| 44 | + param() |
| 45 | + "This Will Not Output" |
| 46 | + Write-Output "This Will Output" |
| 47 | + } |
| 48 | +~~~ |
| 49 | + |
| 50 | +#### Explicit Example 2 |
| 51 | + |
| 52 | + |
| 53 | +~~~PowerShell |
| 54 | + { |
| 55 | + [explicit]{ |
| 56 | + 1,2,3,4 |
| 57 | + echo "Output" |
| 58 | + } |
| 59 | + } | .>PipeScript |
| 60 | +~~~ |
| 61 | + |
| 62 | +#### Help Example 1 |
| 63 | + |
| 64 | + |
| 65 | +~~~PowerShell |
| 66 | + { |
| 67 | + [Help(Synopsis="The Synopsis", Description="A Description")] |
| 68 | + param() |
| 69 | +
|
| 70 | + |
| 71 | + "This Script Has Help, Without Directly Writing Comments" |
| 72 | + |
| 73 | + } | .>PipeScript |
| 74 | +~~~ |
| 75 | + |
| 76 | +#### Help Example 2 |
| 77 | + |
| 78 | + |
| 79 | +~~~PowerShell |
| 80 | + { |
| 81 | + param( |
| 82 | + [Help(Synopsis="X Value")] |
| 83 | + $x |
| 84 | + ) |
| 85 | + } | .>PipeScript |
| 86 | +~~~ |
| 87 | + |
| 88 | +#### Help Example 3 |
| 89 | + |
| 90 | + |
| 91 | +~~~PowerShell |
| 92 | + { |
| 93 | + param( |
| 94 | + [Help("X Value")] |
| 95 | + $x |
| 96 | + ) |
| 97 | + } | .>PipeScript |
| 98 | +~~~ |
| 99 | + |
| 100 | +#### Include Example 1 |
| 101 | + |
| 102 | + |
| 103 | +~~~PowerShell |
| 104 | + { |
| 105 | + [Include("Invoke-PipeScript")]$null |
| 106 | + } | .>PipeScript |
| 107 | +~~~ |
| 108 | + |
| 109 | +#### Include Example 2 |
| 110 | + |
| 111 | + |
| 112 | +~~~PowerShell |
| 113 | + { |
| 114 | + [Include("Invoke-PipeScript")] |
| 115 | + param() |
| 116 | + } | .>PipeScript |
| 117 | +~~~ |
| 118 | + |
| 119 | +#### Include Example 3 |
| 120 | + |
| 121 | + |
| 122 | +~~~PowerShell |
| 123 | + { |
| 124 | + [Include('*-*.ps1')]$psScriptRoot |
| 125 | + } | .>PipeScript |
| 126 | +~~~ |
| 127 | + |
| 128 | +#### Inherit Example 1 |
| 129 | + |
| 130 | + |
| 131 | +~~~PowerShell |
| 132 | + Invoke-PipeScript { |
| 133 | + [inherit("Get-Command")] |
| 134 | + param() |
| 135 | + } |
| 136 | +~~~ |
| 137 | + |
| 138 | +#### Inherit Example 2 |
| 139 | + |
| 140 | + |
| 141 | +~~~PowerShell |
| 142 | + { |
| 143 | + [inherit("gh",Overload)] |
| 144 | + param() |
| 145 | + begin { "ABOUT TO CALL GH"} |
| 146 | + end { "JUST CALLED GH" } |
| 147 | + }.Transpile() |
| 148 | +~~~ |
| 149 | + |
| 150 | +#### Inherit Example 3 |
| 151 | + |
| 152 | + |
| 153 | +~~~PowerShell |
| 154 | + # Inherit Get-Transpiler abstractly and make it output the parameters passed in. |
| 155 | + { |
| 156 | + [inherit("Get-Transpiler", Abstract)] |
| 157 | + param() process { $psBoundParameters } |
| 158 | + }.Transpile() |
| 159 | +~~~ |
| 160 | + |
| 161 | +#### Inherit Example 4 |
| 162 | + |
| 163 | + |
| 164 | +~~~PowerShell |
| 165 | + { |
| 166 | + [inherit("Get-Transpiler", Dynamic, Abstract)] |
| 167 | + param() |
| 168 | + } | .>PipeScript |
| 169 | +~~~ |
| 170 | + |
| 171 | +#### OutputFile Example 1 |
| 172 | + |
| 173 | + |
| 174 | +~~~PowerShell |
| 175 | + Invoke-PipeScript { |
| 176 | + [OutputFile("hello.txt")] |
| 177 | + param() |
| 178 | +
|
| 179 | + 'hello world' |
| 180 | + } |
| 181 | +~~~ |
| 182 | + |
| 183 | +#### OutputFile Example 2 |
| 184 | + |
| 185 | + |
| 186 | +~~~PowerShell |
| 187 | + Invoke-PipeScript { |
| 188 | + param() |
| 189 | +
|
| 190 | + $Message = 'hello world' |
| 191 | + [Save(".\Hello.txt")]$Message |
| 192 | + } |
| 193 | +~~~ |
| 194 | + |
| 195 | +#### ProxyCommand Example 1 |
| 196 | + |
| 197 | + |
| 198 | +~~~PowerShell |
| 199 | + .\ProxyCommand.psx.ps1 -CommandName Get-Process |
| 200 | +~~~ |
| 201 | + |
| 202 | +#### ProxyCommand Example 2 |
| 203 | + |
| 204 | + |
| 205 | +~~~PowerShell |
| 206 | + { |
| 207 | + function [ProxyCommand<'Get-Process'>]GetProcessProxy {} |
| 208 | + } | .>PipeScript |
| 209 | +~~~ |
| 210 | + |
| 211 | +#### ProxyCommand Example 3 |
| 212 | + |
| 213 | + |
| 214 | +~~~PowerShell |
| 215 | + .>ProxyCommand -CommandName Get-Process -RemoveParameter * |
| 216 | +~~~ |
| 217 | + |
| 218 | +#### ProxyCommand Example 4 |
| 219 | + |
| 220 | + |
| 221 | +~~~PowerShell |
| 222 | + Invoke-PipeScript -ScriptBlock {[ProxyCommand('Get-Process')]param()} |
| 223 | +~~~ |
| 224 | + |
| 225 | +#### ProxyCommand Example 5 |
| 226 | + |
| 227 | + |
| 228 | +~~~PowerShell |
| 229 | + Invoke-PipeScript -ScriptBlock { |
| 230 | + [ProxyCommand('Get-Process', |
| 231 | + RemoveParameter='*', |
| 232 | + DefaultParameter={ |
| 233 | + @{id='$pid'} |
| 234 | + })] |
| 235 | + param() |
| 236 | + } |
| 237 | +~~~ |
| 238 | + |
| 239 | +#### ProxyCommand Example 6 |
| 240 | + |
| 241 | + |
| 242 | +~~~PowerShell |
| 243 | + { |
| 244 | + function Get-MyProcess { |
| 245 | + [ProxyCommand('Get-Process', |
| 246 | + RemoveParameter='*', |
| 247 | + DefaultParameter={ |
| 248 | + @{id='$pid'} |
| 249 | + })] |
| 250 | + param() |
| 251 | + } |
| 252 | + } | .>PipeScript |
| 253 | +~~~ |
| 254 | + |
| 255 | +#### RenameVariable Example 1 |
| 256 | + |
| 257 | + |
| 258 | +~~~PowerShell |
| 259 | + { |
| 260 | + [RenameVariable(VariableRename={ |
| 261 | + @{ |
| 262 | + x='x1' |
| 263 | + y='y1' |
| 264 | + } |
| 265 | + })] |
| 266 | + param($x, $y) |
| 267 | + } | .>PipeScript |
| 268 | +~~~ |
| 269 | + |
| 270 | +#### Rest Example 1 |
| 271 | + |
| 272 | + |
| 273 | +~~~PowerShell |
| 274 | + { |
| 275 | + function Get-Sentiment { |
| 276 | + [Rest("http://text-processing.com/api/sentiment/", |
| 277 | + ContentType="application/x-www-form-urlencoded", |
| 278 | + Method = "POST", |
| 279 | + BodyParameter="Text", |
| 280 | + ForeachOutput = { |
| 281 | + $_ | Select-Object -ExpandProperty Probability -Property Label |
| 282 | + } |
| 283 | + )] |
| 284 | + param() |
| 285 | + } |
| 286 | + } | .>PipeScript | Set-Content .\Get-Sentiment.ps1 |
| 287 | +~~~ |
| 288 | + |
| 289 | +#### Rest Example 2 |
| 290 | + |
| 291 | + |
| 292 | +~~~PowerShell |
| 293 | + Invoke-PipeScript { |
| 294 | + [Rest("http://text-processing.com/api/sentiment/", |
| 295 | + ContentType="application/x-www-form-urlencoded", |
| 296 | + Method = "POST", |
| 297 | + BodyParameter="Text", |
| 298 | + ForeachOutput = { |
| 299 | + $_ | Select-Object -ExpandProperty Probability -Property Label |
| 300 | + } |
| 301 | + )] |
| 302 | + param() |
| 303 | + } -Parameter @{Text='wow!'} |
| 304 | +~~~ |
| 305 | + |
| 306 | +#### Rest Example 3 |
| 307 | + |
| 308 | + |
| 309 | +~~~PowerShell |
| 310 | + { |
| 311 | + [Rest("https://api.github.com/users/{username}/repos", |
| 312 | + QueryParameter={"type", "sort", "direction", "page", "per_page"} |
| 313 | + )] |
| 314 | + param() |
| 315 | + } | .>PipeScript |
| 316 | +~~~ |
| 317 | + |
| 318 | +#### Rest Example 4 |
| 319 | + |
| 320 | + |
| 321 | +~~~PowerShell |
| 322 | + Invoke-PipeScript { |
| 323 | + [Rest("https://api.github.com/users/{username}/repos", |
| 324 | + QueryParameter={"type", "sort", "direction", "page", "per_page"} |
| 325 | + )] |
| 326 | + param() |
| 327 | + } -UserName StartAutomating |
| 328 | +~~~ |
| 329 | + |
| 330 | +#### Rest Example 5 |
| 331 | + |
| 332 | + |
| 333 | +~~~PowerShell |
| 334 | + { |
| 335 | + [Rest("http://text-processing.com/api/sentiment/", |
| 336 | + ContentType="application/x-www-form-urlencoded", |
| 337 | + Method = "POST", |
| 338 | + BodyParameter={@{ |
| 339 | + Text = ' |
| 340 | + [Parameter(Mandatory,ValueFromPipelineByPropertyName)] |
| 341 | + [string] |
| 342 | + $Text |
| 343 | + ' |
| 344 | + }})] |
| 345 | + param() |
| 346 | + } | .>PipeScript |
| 347 | +~~~ |
| 348 | + |
| 349 | + |
| 350 | + |
| 351 | + |
0 commit comments