Requirements icon indicating copy to clipboard operation
Requirements copied to clipboard

Format-Checklist does not accept parameter input

Open bstrautin opened this issue 7 years ago • 4 comments

Format-Checklist fails when passing a RequirementEvent[] object as a parameter. It should format the objects as it does when they are passed in from the pipeline.

Error:

Format-Checklist : Cannot bind parameter 'Date' to the target. Exception setting "Date": "Cannot convert null to type
"System.DateTime"."
At line:25 char:1
+ Format-Checklist -RequirementEvent $output   # fails
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : WriteError: (:) [Format-Checklist], ParameterBindingException
    + FullyQualifiedErrorId : ParameterBindingFailed,Format-Checklist

Code to reproduce:

$mySystem = [collections.generic.list[int]]::new()

$requirements = @(
    @{
        Name     = "Resource 1"
        Describe = "Resource 1 is present in the system"
        Test     = { $mySystem -contains 1 }
        Set      = { $mySystem.Add(1) | Out-Null; Start-Sleep 1 }
    },
    @{
        Name     = "Resource 2"
        Describe = "Resource 2 is present in the system"
        Test     = { $mySystem -contains 2 }
        Set      = { $mySystem.Add(2) | Out-Null; Start-Sleep 1 }
    }
)

$output = $requirements | Invoke-Requirement

$output | Format-Table | Out-Host            # works
Format-Table -InputObject $output | Out-Host # works

$output | Format-Checklist | Out-Host        # works
Format-Checklist -RequirementEvent $output   # fails

bstrautin avatar Sep 08 '19 11:09 bstrautin

Seems like

  1. the parameter attribute should be changed from ValueFromPipeline to ValueFromPipelineByPropertyName
  2. the process block should wrap a foreach loop around the current process block content
  3. update the iterated value from $_ to $event or something similar

chriskuech avatar Sep 08 '19 18:09 chriskuech

I should probably add that I'm not sure why anyone would do this. Format-Checklist is meant for real-time updating of the host. If you want non-realtime, you're probably better off using the other Format-* cmdlets that support stream redirection.

chriskuech avatar Sep 08 '19 18:09 chriskuech

Users' wants and developers' expectations are rarely in sync. :-)

bstrautin avatar Sep 08 '19 22:09 bstrautin

Well, my attempted solution seemed to stop the formatters from accepting pipeline input. Not sure if anyone has any ideas here...

chriskuech avatar Sep 13 '19 02:09 chriskuech