{-# LANGUAGE NoImplicitPrelude #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE TypeApplications #-}
module Headroom.FileType
( configByFileType
, fileTypeByExt
, listExtensions
)
where
import Headroom.Types ( FileType(..)
, HeaderConfig(..)
, HeadersConfig(..)
)
import Headroom.Types.EnumExtra ( EnumExtra(..) )
import RIO
import qualified RIO.List as L
fileTypeByExt :: HeadersConfig
-> Text
-> Maybe FileType
fileTypeByExt :: HeadersConfig -> Text -> Maybe FileType
fileTypeByExt config :: HeadersConfig
config ext :: Text
ext =
(FileType -> Bool) -> [FileType] -> Maybe FileType
forall (t :: * -> *) a. Foldable t => (a -> Bool) -> t a -> Maybe a
L.find (Text -> [Text] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
elem Text
ext ([Text] -> Bool) -> (FileType -> [Text]) -> FileType -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. HeadersConfig -> FileType -> [Text]
listExtensions HeadersConfig
config) (EnumExtra FileType => [FileType]
forall a. EnumExtra a => [a]
allValues @FileType)
listExtensions :: HeadersConfig
-> FileType
-> [Text]
listExtensions :: HeadersConfig -> FileType -> [Text]
listExtensions config :: HeadersConfig
config fileType :: FileType
fileType =
HeaderConfig -> [Text]
hcFileExtensions (HeadersConfig -> FileType -> HeaderConfig
configByFileType HeadersConfig
config FileType
fileType)
configByFileType :: HeadersConfig
-> FileType
-> HeaderConfig
configByFileType :: HeadersConfig -> FileType -> HeaderConfig
configByFileType HeadersConfig {..} fileType :: FileType
fileType = case FileType
fileType of
C -> HeaderConfig
hscC
CPP -> HeaderConfig
hscCpp
CSS -> HeaderConfig
hscCss
Haskell -> HeaderConfig
hscHaskell
HTML -> HeaderConfig
hscHtml
Java -> HeaderConfig
hscJava
JS -> HeaderConfig
hscJs
Rust -> HeaderConfig
hscRust
Scala -> HeaderConfig
hscScala
Shell -> HeaderConfig
hscShell