Merge pull request #15 from DunetsNM/feature/cmd-line-cabal-stack-switch

--cabal and --stack command line switches
This commit is contained in:
Avi Dessauer 2020-07-07 00:56:59 -04:00 committed by GitHub
commit eb606df6c3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 7 deletions

View File

@ -15,17 +15,12 @@ import Hie.Yaml
import System.Directory
import System.Directory.Internal
import System.FilePath.Posix
import System.Environment
main :: IO ()
main = do
pwd <- getCurrentDirectory
files <- listDirectory pwd
let name =
if | any (("dist-newstyle" ==) . takeFileName) files -> "cabal"
| any ((".stack-work" ==) . takeFileName) files -> "stack"
| any (("cabal.project" ==) . takeFileName) files -> "cabal"
| any (("stack.yaml" ==) . takeFileName) files -> "stack"
| otherwise -> "cabal"
name <- resolveName pwd
cfs <- runMaybeT $ case name of
"cabal" -> cabalPkgs pwd
_ -> stackYamlPkgs pwd
@ -35,3 +30,19 @@ main = do
<> "\n You may need to run stack build."
pkgs <- catMaybes <$> mapM (nestedPkg pwd) (concat cfs)
putStr <$> hieYaml name $ fmtPkgs name pkgs
resolveName :: FilePath -> IO String
resolveName pwd = do
args <- getArgs
files <- listDirectory pwd
let fileNames = map takeFileName files
name =
if | "--cabal" `elem` args -> "cabal"
| "--stack" `elem` args -> "stack"
| "dist-newstyle" `elem` fileNames -> "cabal"
| ".stack-work" `elem` fileNames -> "stack"
| "cabal.project" `elem` fileNames -> "cabal"
| "stack.yaml" `elem` fileNames -> "stack"
| otherwise -> "cabal"
return name

12
hie.yaml.cbl Normal file
View File

@ -0,0 +1,12 @@
# Rename this file to hie.yaml to open this project in HIE and use Cabal as build system
cradle:
cabal:
- path: "src"
component: "lib:implicit-hie"
- path: "app/Main.hs"
component: "implicit-hie:exe:gen-hie"
- path: "test"
component: "implicit-hie:test:implicit-hie-test"

12
hie.yaml.stack Normal file
View File

@ -0,0 +1,12 @@
# Rename this file to hie.yaml to open this project in HIE and use Stack as build system
cradle:
stack:
- path: "./src"
component: "implicit-hie:lib"
- path: "./app/Main.hs"
component: "implicit-hie:exe:gen-hie"
- path: "./test"
component: "implicit-hie:test:implicit-hie-test"