gdritter repos charter / 4a49aff
Make module handling nicer/more general Getty Ritter 6 years ago
4 changed file(s) with 19 addition(s) and 14 deletion(s). Collapse all Expand all
1919 | SetRoot T.Text
2020 | AddDep T.Text
2121 | AddUsualDeps
22 | AddMod T.Text
2223 deriving (Eq, Show)
2324
2425 options :: [Opt.OptDescr Option]
2627 [ Opt.Option ['b'] ["bin"]
2728 (Opt.ReqArg (AddBinary . T.pack) "PROGRAM NAME")
2829 "Add another binary target to this Cabal file"
30 , Opt.Option ['m'] ["module"]
31 (Opt.ReqArg (AddMod . T.pack) "MODULE NAME")
32 "Add another library module to this Cabal file"
2933 , Opt.Option ['r'] ["root"]
3034 (Opt.ReqArg (SetRoot . T.pack) "DIRECTORY")
3135 "Set the root directory for this project"
6266 where
6367 go (AddBinary n) proj =
6468 proj & C.binDetails %~ (C.mkBinary n :)
69 go (AddMod m) proj =
70 proj & C.libDetails %~ fmap (& C.libMods %~ (m :))
6571 go (SetCategory s) proj =
6672 proj & C.projectDetails . C.projectCategory .~ Just s
6773 go (SetSynopsis s) proj =
3535 , _execDeps = []
3636 }
3737
38 mkLibrary :: T.Text -> LibraryDetails
39 mkLibrary n = LibraryDetails
40 { _libExposedModules = [capitalize n]
38 mkLibrary :: LibraryDetails
39 mkLibrary = LibraryDetails
40 { _libMods = []
4141 , _libDeps = []
4242 }
4343
5959 projectBin deets =
6060 mkProject deets & binDetails .~ [ bin ]
6161 & libDetails .~ Just lib
62 where bin = mkBinary name & execDeps .~ ["name"]
63 lib = mkLibrary name
62 where bin = mkBinary name & execDeps .~ [name]
63 lib = mkLibrary & libMods .~ [capitalize name]
6464 name = deets^.projectName
6565
6666 usualDeps :: [T.Text]
7373
7474 library :: ProjectDetails -> Project
7575 library deets =
76 mkProject deets & libDetails .~ Just lib
77 where
78 lib = mkLibrary (deets^.projectName)
76 mkProject deets & libDetails .~ Just mkLibrary
7977
8078 mkdirBase :: T.Text -> [T.Text] -> IO ()
8179 mkdirBase base fp = do
128126 case (pr^.libDetails) of
129127 Nothing -> return ()
130128 Just lib -> do
131 forM_ (lib^.libExposedModules) $ \ m -> do
132 let modPath = "src" : T.splitOn "." (m <> ".hs")
133 write modPath (defaultLib m)
129 forM_ (lib^.libMods) $ \ m -> do
130 let modPath = "src" : T.splitOn "." m
131 modPath' = init modPath ++ [last modPath <> ".hs"]
132 write modPath' (defaultLib m)
134133
135134 forM_ (pr^.binDetails) $ \e -> do
136135 write [e^.execDir, "Main.hs"] defaultBin
4242 , " default-extensions: ScopedTypeVariables"
4343 ] <> mods
4444 where
45 mods = case lib^.libExposedModules of
45 mods = case lib^.libMods of
4646 [] -> []
4747 (x:xs) ->
4848 (" exposed-modules: " <> x) :
1717 }
1818
1919 data LibraryDetails = LibraryDetails
20 { _libExposedModules :: [T.Text]
21 , _libDeps :: [T.Text]
20 { _libMods :: [T.Text]
21 , _libDeps :: [T.Text]
2222 }
2323
2424 data ExecutableDetails = ExecutableDetails