freckle / stackctl

Manage CloudFormation Stacks through specifications
MIT License
14 stars 1 forks source link

Refactor RequiredVersion, add instances #35

Closed pbrisbin closed 1 year ago

pbrisbin commented 1 year ago

https://app.asana.com/0/13211253278157/1203652238195585/f

We need Eq to use RequiredVersion in tests. And we need ToJSON for structured logging.

The current Show instance was custom and doesn't render a valid Haskell syntax, which is an anti-pattern. The reason for this is that the requiredVersionCompare member was itself a function, so we couldn't just derive a stock Show. By removing that member, and instead holding a new RequiredVersionOp enumeration that can be converted to it, we can now derive stock Eq and Show. The new requiredVersionOpToText and requiredVersionOpCompare functions will need to be kept in sync, but I don't see them changing very frequently (and we have great tests here).

We retain the more human-readable format in the new ToJSON instance, because we need it in FromJSON (to parse Yaml correctly) and it must of course round-trip with ToJSON.