implicit-hie/app/Main.hs

38 lines
1.1 KiB
Haskell
Raw Normal View History

2020-05-01 03:48:32 +03:00
{-# LANGUAGE MultiWayIf #-}
2020-04-24 03:48:49 +03:00
module Main where
2020-05-01 03:48:32 +03:00
import Control.Monad
import Control.Monad.Trans.Maybe
2020-04-25 07:28:20 +03:00
import Data.Attoparsec.Text
import Data.List
import Data.Maybe
2020-05-01 03:48:32 +03:00
import qualified Data.Text as T
2020-04-25 07:28:20 +03:00
import qualified Data.Text.IO as T
2020-05-01 02:35:00 +03:00
import Hie.Cabal.Parser
2020-05-09 09:10:48 +03:00
import Hie.Locate
import Hie.Yaml
2020-05-01 03:48:32 +03:00
import System.Directory
2020-05-02 03:28:14 +03:00
import System.Directory.Internal
2020-05-01 03:48:32 +03:00
import System.FilePath.Posix
2020-04-24 03:48:49 +03:00
main :: IO ()
2020-04-25 07:28:20 +03:00
main = do
2020-05-02 03:28:14 +03:00
pwd <- getCurrentDirectory
files <- listDirectory pwd
2020-05-09 08:26:07 +03:00
let name =
if | any (("dist-newstyle" ==) . takeFileName) files -> "cabal"
| any ((".stack-work" ==) . takeFileName) files -> "stack"
| any (("cabal.project" ==) . takeFileName) files -> "cabal"
2020-05-09 08:26:07 +03:00
| any (("stack.yaml" ==) . takeFileName) files -> "stack"
| otherwise -> "cabal"
cfs <- runMaybeT $ case name of
"cabal" -> cabalPkgs pwd
_ -> stackYamlPkgs pwd
2020-05-02 03:28:14 +03:00
when (null cfs) $ error $
"No .cabal files found under"
<> pwd
<> "\n You may need to run stack build."
pkgs <- catMaybes <$> mapM (nestedPkg pwd) (concat cfs)
2020-05-09 08:26:07 +03:00
putStr <$> hieYaml name $ fmtPkgs name pkgs