-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Sketch-PipelineOperator-WasOkayTest.md
- Loading branch information
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
```ps1 | ||
function HandleStuff { | ||
process { | ||
if($_ -le 5) { | ||
write-verbose 'was <= ?' -Verbose | ||
write-error 'invalid range' } | ||
} | ||
} | ||
function Test-WasOk { 'π' } | ||
function GetFallback { 400 } | ||
``` | ||
### Using `||` as a fallback ? | ||
|
||
```sh | ||
Can it run fallback when there's an error? | ||
0,3,10 | HandleStuff || GetFallback | ||
``` | ||
output | ||
``` | ||
VERBOSE: was <= ? | ||
HandleStuff: invalid range | ||
VERBOSE: was <= ? | ||
HandleStuff: invalid range | ||
``` | ||
`GetFallback` is never called because the final value in the pipeline was not an error | ||
### Using `&&` to run command2 only if command1 is successful? | ||
0,3,10 | HandleStuff && Test-WasOk | ||
```ps1 | ||
> 100 | HandleStuff && Test-WasOk | ||
# π | ||
> 3 | HandleStuff && Test-WasOk | ||
VERBOSE: was <= ? | ||
HandleStuff: invalid range | ||
π | ||
``` | ||
```ps1 | ||
3, 10 | HandleStuff && Test-WasOk | ||
VERBOSE: was <= ? | ||
HandleStuff: invalid range | ||
π | ||
Pwsh 7.4.1> [22] π | ||
10, 3 | HandleStuff && Test-WasOk | ||
VERBOSE: was <= ? | ||
HandleStuff: invalid range | ||
π | ||
Pwsh 7.4.1> [23] π | ||
10, 3, 99 | HandleStuff && Test-WasOk | ||
VERBOSE: was <= ? | ||
HandleStuff: invalid range | ||
π | ||
``` |