@@ -84,6 +84,9 @@ data PartialCommandLineArgs = PartialCommandLineArgs
8484 deriving stock (Generic , Show , Eq )
8585 deriving Monoid via GenericMonoid PartialCommandLineArgs
8686
87+ instance (Show a , Show b ) => Pretty (Map a b )
88+ instance Pretty PartialCommandLineArgs
89+
8790instance Semigroup PartialCommandLineArgs where
8891 x <> y = PartialCommandLineArgs
8992 { partialCommandLineArgsKeyBased =
@@ -313,6 +316,16 @@ data PartialPostgresPlan = PartialPostgresPlan
313316 deriving Semigroup via GenericSemigroup PartialPostgresPlan
314317 deriving Monoid via GenericMonoid PartialPostgresPlan
315318
319+ instance Pretty Client. Options
320+ instance Pretty Char
321+ instance Show a => Pretty (Last a )
322+
323+ instance Pretty PartialPostgresPlan where
324+ pretty PartialPostgresPlan {.. } = unlines
325+ [ " partialPostgresPlanProcessConfig: " <> pretty partialPostgresPlanProcessConfig
326+ , " partialPostgresPlanClientConfig: " <> pretty partialPostgresPlanClientConfig
327+ ]
328+
316329-- | Turn a 'PartialPostgresPlan' into a 'PostgresPlan'. Fails if any
317330-- values are missing.
318331completePostgresPlan :: PartialPostgresPlan -> Either [String ] PostgresPlan
@@ -340,6 +353,40 @@ data PartialPlan = PartialPlan
340353 deriving Semigroup via GenericSemigroup PartialPlan
341354 deriving Monoid via GenericMonoid PartialPlan
342355
356+ class Pretty a where
357+ pretty :: a -> String
358+
359+ default pretty :: Show a => a -> String
360+ pretty = show
361+
362+ instance Pretty a => Pretty (Maybe a ) where
363+ pretty = maybe " " pretty
364+
365+ instance Pretty a => Pretty [a ] where
366+ pretty = unlines . map pretty
367+
368+ instance Pretty a => Pretty (Lastoid a ) where
369+ pretty = \ case
370+ Replace x -> " Replace: " <> pretty x
371+ Mappend x -> " Mappend: " <> pretty x
372+
373+ instance Pretty PartialProcessConfig where
374+ pretty PartialProcessConfig {.. } = unlines
375+ [ " partialProcessConfigEnvVars: " <> pretty partialProcessConfigEnvVars
376+ , " partialProcessConfigCmdLine: " <> pretty partialProcessConfigCmdLine
377+ ]
378+
379+ instance Pretty PartialPlan where
380+ pretty PartialPlan {.. } = unlines
381+ [ " partialPlanInitDb: " <> pretty partialPlanInitDb
382+ , " partialPlanCreateDb: " <> pretty partialPlanCreateDb
383+ , " partialPlanPostgres: " <> pretty partialPlanPostgres
384+ , " partialPlanConfig: " <> pretty partialPlanConfig
385+ , " partialPlanDataDirectory: " <> pretty partialPlanDataDirectory
386+ ]
387+
388+
389+ -- TODO treat Mappend in the initdb and createdb as a Nothing
343390-- | Turn a 'PartialPlan' into a 'Plan'. Fails if any values are missing.
344391completePlan :: PartialPlan -> Either [String ] Plan
345392completePlan PartialPlan {.. } = validationToEither $ do
@@ -387,6 +434,10 @@ data Config = Config
387434 deriving Semigroup via GenericSemigroup Config
388435 deriving Monoid via GenericMonoid Config
389436
437+ -- Instead of interpreting the Replace and Mappend different
438+ -- I can use a different Monoid for Maybe that annilates with
439+ -- Nothing. The I can control create db runs or nothing by
440+ -- combine until it is disabled.
390441-- | Create a 'PartialPlan' that sets the command line options of all processes
391442-- (@initdb@, @postgres@ and @createdb@) using a
392443toPlan
@@ -446,8 +497,9 @@ initConfig Config {..} = evalContT $ do
446497 (initDirectoryType " tmp-postgres-data" configDataDir) shutdownDirectoryType
447498 let hostAndDirPartial = toPlan port resourcesSocket $
448499 toFilePath resourcesDataDir
449- resourcesPlan <- lift $ either (throwIO . CompletePlanFailed ) pure $
450- completePlan $ hostAndDirPartial <> configPlan
500+ combinedPlan = hostAndDirPartial <> configPlan
501+ resourcesPlan <- lift $ either (throwIO . CompletePlanFailed (pretty combinedPlan)) pure $
502+ completePlan combinedPlan
451503 pure Resources {.. }
452504
453505-- | Free the temporary resources created by 'initConfig'
0 commit comments