xecuteAndMonitorCommand :: Params -> MonitorOptions -> Command -> IO ()
executeAndMonitorCommand params MonitorOptions{..} command
  | monitor = do
        getDuration <- startDuration
        pid <- Posix.forkProcess (executeCommand' params command)
        exitCode <- getProcessStatus pid
        duration <- getDuration
        out params stdout
            ("Action took: " <> Pretty.viaShow duration <> Pretty.line)
        -- TODO: Value of type `NotifyConfig` should be part of `Config`.
        doNotifyWhen defNotifyConfig True notificationMessage exitCode
        exitWith exitCode

  | otherwise =
        executeCommand' params command
  where
    getProcessStatus :: Posix.ProcessID -> IO ExitCode
    getProcessStatus pid =
        Posix.getProcessStatus True True pid >>= \case
            Just (Posix.Exited exitCode) -> pure exitCode
            Just Posix.Terminated{} -> pure (ExitFailure 1)
            Just Posix.Stopped{} -> getProcessStatus pid
            Nothing -> getProcessStatus pid

executeAndMonitorCommand :: Params -> MonitorOptions -> Command -> IO ()
executeAndMonitorCommand params MonitorOptions{..} command
  | monitor = do
        getDuration <- startDuration
        pid <- Posix.forkProcess (executeCommand' params command)
        exitCode <- getProcessStatus pid
        duration <- getDuration
        out params stdout
            ("Action took: " <> Pretty.viaShow duration <> Pretty.line)
        -- TODO: Value of type `NotifyConfig` should be part of `Config`.
        doNotifyWhen defNotifyConfig True notificationMessage exitCode
        exitWith exitCode

  | otherwise =
        executeCommand' params command
  where
    getProcessStatus :: Posix.ProcessID -> IO ExitCode
    getProcessStatus pid =
        Posix.getProcessStatus True True pid >>= \case
            Just (Posix.Exited exitCode) -> pure exitCode
            Just Posix.Terminated{} -> pure (ExitFailure 1)
            Just Posix.Stopped{} -> getProcessStatus pid
            Nothing -> getProcessStatus pid
executeAndMonitorCommand params MonitorOptions{..} command
  | monitor = do
        getDuration <- startDuration
        pid <- Posix.forkProcess (executeCommand' params command)
        exitCode <- getProcessStatus pid
        duration <- getDuration
        out params stdout
            ("Action took: " <> Pretty.viaShow duration <> Pretty.line)
        -- TODO: Value of type `NotifyConfig` should be part of `Config`.
        doNotifyWhen defNotifyConfig True notificationMessage exitCode
        exitWith exitCode

  | otherwise =
        executeCommand' params command
  where
    getProcessStatus :: Posix.ProcessID -> IO ExitCode
    getProcessStatus pid =
        Posix.getProcessStatus True True pid >>= \case
            Just (Posix.Exited exitCode) -> pure exitCode
            Just Posix.Terminated{} -> pure (ExitFailure 1)
            Just Posix.Stopped{} -> getProcessStatus pid
            Nothing -> getProcessStatus pid