implicit-hie/app/Main.hs

28 lines
907 B
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
2020-04-25 07:28:20 +03:00
import Data.Attoparsec.Text
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
import Hie.Yaml
2020-05-01 03:48:32 +03:00
import System.Directory
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-01 03:48:32 +03:00
files <- listDirectory =<< getCurrentDirectory
let path = filter ((".cabal" ==) . takeExtension) files
sOrC =
if | any ((".stack-work" ==) . takeFileName) files -> stackHieYaml
| any (("dist-newstyle" ==) . takeFileName) files -> cabalHieYaml
| any (("stack.yaml" ==) . takeFileName) files -> stackHieYaml
| otherwise -> cabalHieYaml
2020-05-01 03:48:32 +03:00
when (null path) $ error "No .cabal file found!\n You may need to run stack build."
file <- T.readFile $ head path
2020-05-01 03:51:44 +03:00
case parseOnly parsePackage file of
2020-05-01 03:59:13 +03:00
Right r -> T.putStr $ sOrC r
2020-04-25 07:28:20 +03:00
_ -> error "Could not parse *.cabal file"