-- | Parse YAML file and return either:
-- * The entry matching the given name, or
-- * The first entry if no name is provided
do
parseResult <- parseConfigFile file
case parseResult of
Left err -> pure $ Left err
Right cfg -> case mName of
Just cfgNameStr -> case find (\e -> T.unpack (name e) == cfgNameStr) cfg of
Just entry -> pure $ Right entry
Nothing -> pure $ Left $ "No config entry named: " ++ cfgNameStr
Nothing -> case listToMaybe cfg of
Just entry -> pure $ Right entry
Nothing -> pure $ Left "YAML config is empty"