module Hi.FilePath
(
rewritePath
) where
import Hi.Template (untemplate)
import Hi.Types
import Hi.Utils
import Data.List
import Data.List.Split (splitOn)
import Data.Maybe (fromJust)
import System.FilePath (joinPath)
rewritePath :: [Option] -> FilePath -> FilePath
rewritePath options =
rename1 . rename2 . untemplate
where
rename1 = replace "package-name" $ fromJust $ lookupArg "packageName" options
rename2 = replace "ModuleName" $ toDir . fromJust $ lookupArg "moduleName" options
toDir :: String -> FilePath
toDir = joinPath . splitOn "."
replace :: Eq a => [a] -> [a] -> [a] -> [a]
replace a b = foldl1 (++) . intersperse b . splitOn a