Skip to content

--cabal and --stack command line switches #15

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions app/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 changes: 12 additions & 0 deletions hie.yaml.cbl
Original file line number Diff line number Diff line change
@@ -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 changes: 12 additions & 0 deletions hie.yaml.stack
Original file line number Diff line number Diff line change
@@ -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"