makeSureOptionsAreValid :: (Options, ()) -> IO (FilePath, Int)
makeSureOptionsAreValid (Options {..}, ()) =
       makeSurePortIsValid
    >> makeSureCSVExists
    >> return (commonFood, port)
  where
    -- | Checks if specified value is valid registered port,
    -- please see https://en.wikipedia.org/wiki/Registered_port for details.
    makeSurePortIsValid :: IO ()
    makeSurePortIsValid =
        when (port < minPort || port > maxPort) reportAboutWrongPort
      where
        minPort = 1024  -- There's no reasons to run this service on a privileged port. ;-)
        maxPort = 49151
        reportAboutWrongPort = die $
            "Please specify valid registered port, integer from "
            <> show minPort <> " to " <> show maxPort <> "."

    makeSureCSVExists :: IO ()
    makeSureCSVExists =
        unlessM (doesDirectoryExist commonFood) reportAboutCSVMissing
      where
        reportAboutCSVMissing = die $
            "No such directory '"
            <> commonFood
            <> "', you can specify path to a directory with .csv-file via '--food' option."
makeSureOptionsAreValid :: (Options, ()) -> IO (FilePath, Int)
makeSureOptionsAreValid (Options {..}, ()) =
       makeSurePortIsValid
    >> makeSureCSVExists
    >> return (commonFood, port)
  where
    -- | Checks if specified value is valid registered port,
    -- please see https://en.wikipedia.org/wiki/Registered_port for details.
    makeSurePortIsValid :: IO ()
    makeSurePortIsValid =
        when (port < minPort || port > maxPort) reportAboutWrongPort
      where
        minPort = 1024  -- There's no reasons to run this service on a privileged port. ;-)
        maxPort = 49151
        reportAboutWrongPort = die $
            "Please specify valid registered port, integer from "
            <> show minPort <> " to " <> show maxPort <> "."

    makeSureCSVExists :: IO ()
    makeSureCSVExists =
        unlessM (doesDirectoryExist commonFood) reportAboutCSVMissing
      where
        reportAboutCSVMissing = die $
            "No such directory '"
            <> commonFood
            <> "', you can specify path to a directory with .csv-file via '--food' option."
makeSureOptionsAreValid (Options {..}, ()) =
       makeSurePortIsValid
    >> makeSureCSVExists
    >> return (commonFood, port)
  where
    -- | Checks if specified value is valid registered port,
    -- please see https://en.wikipedia.org/wiki/Registered_port for details.
    makeSurePortIsValid :: IO ()
    makeSurePortIsValid =
        when (port < minPort || port > maxPort) reportAboutWrongPort
      where
        minPort = 1024  -- There's no reasons to run this service on a privileged port. ;-)
        maxPort = 49151
        reportAboutWrongPort = die $
            "Please specify valid registered port, integer from "
            <> show minPort <> " to " <> show maxPort <> "."

    makeSureCSVExists :: IO ()
    makeSureCSVExists =
        unlessM (doesDirectoryExist commonFood) reportAboutCSVMissing
      where
        reportAboutCSVMissing = die $
            "No such directory '"
            <> commonFood
            <> "', you can specify path to a directory with .csv-file via '--food' option."