Skip to content

Commit eb606df

Browse files
authored
Merge pull request #15 from DunetsNM/feature/cmd-line-cabal-stack-switch
--cabal and --stack command line switches
2 parents 2dabc0e + a6c91a8 commit eb606df

File tree

3 files changed

+42
-7
lines changed

3 files changed

+42
-7
lines changed

app/Main.hs

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,12 @@ import Hie.Yaml
1515
import System.Directory
1616
import System.Directory.Internal
1717
import System.FilePath.Posix
18+
import System.Environment
1819

1920
main :: IO ()
2021
main = do
2122
pwd <- getCurrentDirectory
22-
files <- listDirectory pwd
23-
let name =
24-
if | any (("dist-newstyle" ==) . takeFileName) files -> "cabal"
25-
| any ((".stack-work" ==) . takeFileName) files -> "stack"
26-
| any (("cabal.project" ==) . takeFileName) files -> "cabal"
27-
| any (("stack.yaml" ==) . takeFileName) files -> "stack"
28-
| otherwise -> "cabal"
23+
name <- resolveName pwd
2924
cfs <- runMaybeT $ case name of
3025
"cabal" -> cabalPkgs pwd
3126
_ -> stackYamlPkgs pwd
@@ -35,3 +30,19 @@ main = do
3530
<> "\n You may need to run stack build."
3631
pkgs <- catMaybes <$> mapM (nestedPkg pwd) (concat cfs)
3732
putStr <$> hieYaml name $ fmtPkgs name pkgs
33+
34+
resolveName :: FilePath -> IO String
35+
resolveName pwd = do
36+
args <- getArgs
37+
files <- listDirectory pwd
38+
let fileNames = map takeFileName files
39+
name =
40+
if | "--cabal" `elem` args -> "cabal"
41+
| "--stack" `elem` args -> "stack"
42+
| "dist-newstyle" `elem` fileNames -> "cabal"
43+
| ".stack-work" `elem` fileNames -> "stack"
44+
| "cabal.project" `elem` fileNames -> "cabal"
45+
| "stack.yaml" `elem` fileNames -> "stack"
46+
| otherwise -> "cabal"
47+
return name
48+

hie.yaml.cbl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Rename this file to hie.yaml to open this project in HIE and use Cabal as build system
2+
3+
cradle:
4+
cabal:
5+
- path: "src"
6+
component: "lib:implicit-hie"
7+
8+
- path: "app/Main.hs"
9+
component: "implicit-hie:exe:gen-hie"
10+
11+
- path: "test"
12+
component: "implicit-hie:test:implicit-hie-test"

hie.yaml.stack

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Rename this file to hie.yaml to open this project in HIE and use Stack as build system
2+
3+
cradle:
4+
stack:
5+
- path: "./src"
6+
component: "implicit-hie:lib"
7+
8+
- path: "./app/Main.hs"
9+
component: "implicit-hie:exe:gen-hie"
10+
11+
- path: "./test"
12+
component: "implicit-hie:test:implicit-hie-test"

0 commit comments

Comments
 (0)