Closed andreasjordan closed 2 years ago
Found the problem:
The test if ($CookingState)
(line 111) does not use the string but the index of the enum - and that is 0 as it is the first one and so it is false. You should test for the $PSBoundParameters and see if the Parameter was used.
Not a problem but not nice: When piping to Set-Vegetable, $count is always set because of [Parameter(ValueFromPipelineByPropertyName)]
. So the Count property is always set as you can see in the verbose output.
Code for copy-paste:
Get-Vegetable -Name zucchini | Set-Vegetable -CookingState Grilled -Passthru
Get-Vegetable -Name zucchini | Set-Vegetable -CookingState Baked -Passthru -Verbose
Get-Vegetable -Name zucchini | Set-Vegetable -CookingState Raw -Passthru -Verbose
$CookingState = 'Raw'
if ($CookingState) { 'will work' } else { 'will not work' }
$CookingState = [PSTeachingTools.VegStatus]::Raw
if ($CookingState) { 'will work' } else { 'will not work' }
This is one of the challenges when working with classes and enums in your own code. This wasn't an issue the way I was using the commands for beginning PowerShell classes but there is room for improvement.
The other problem I see is that I never finished setting up parameter sets. Working on cleaning this up.
I think I have this sorted out. Update to v4.2.0 from the PowerShell Gallery and try again.
Yes, it works.
Only drawback: Verbose is a bit noisey now:
I think $PSBoundParameters | Out-String | Write-Verbose
should be $PSBoundParameters | Out-String | Write-Debug
.
Verbose is supposed to be noisy. But I get your point. Lately, I've started balancing these kinds of details between verbose and debug streams. Although, because these commands are designed as teaching tools, I don't mind the extra "noise".
Totally agree - thanks for the quick fix.
I can change the CookedState from Raw to something else, but not back to Raw.
I'm too blind to see where in the code this is tested - can you help me?