@@ -1,7 +1,8 @@
11{-# LANGUAGE LambdaCase #-}
22{-# LANGUAGE OverloadedStrings #-}
33module Obelisk.Command.Project
4− ( initProject
4+ ( InitSource (..)
5+ , initProject
56 , findProjectObeliskCommand
67 , findProjectRoot
78 , inProjectShell
@@ -20,6 +21,7 @@ import System.Exit
2021import System.FilePath
2122import System.IO
2223import System.Posix (FileStatus, getFileStatus , deviceID, fileID, getRealUserID , fileOwner, fileMode, UserID)
24+import System.Posix.Files
2325import System.Process
2426
2527import GitHub.Data.Name (Name)
@@ -43,12 +45,25 @@ obeliskSourceWithBranch branch = ThunkSource_GitHub $ GitHubSource
4345 , _gitHubSource_private = True
4446 }
4547
46−initProject :: FilePath -> Maybe (Name Branch) -> IO ()
47−initProject target branch = do
48− let obDir = target </> ".obelisk"
48+data InitSource
49+ = InitSource_Default
50+ | InitSource_Branch (Name Branch)
51+ | InitSource_Symlink FilePath
52+
53+-- | Create a new project rooted in the current directory
54+initProject :: InitSource -> IO ()
55+initProject source = do
56+ let obDir = ".obelisk"
4957 implDir = obDir </> "impl"
5058 createDirectory obDir
51− createThunkWithLatest implDir $ maybe obeliskSource obeliskSourceWithBranch branch
59+ case source of
60+ InitSource_Default -> createThunkWithLatest implDir obeliskSource
61+ InitSource_Branch branch -> createThunkWithLatest implDir $ obeliskSourceWithBranch branch
62+ InitSource_Symlink path -> do
63+ let symlinkPath = if isAbsolute path
64+ then path
65+ else ".." </> path
66+ createSymbolicLink symlinkPath implDir
5267 _ <- nixBuildAttrWithCache implDir "command"
5368 --TODO: We should probably handoff to the impl here
5469 skeleton <- nixBuildAttrWithCache implDir "skeleton" --TODO: I don't think there's actually any reason to cache this
@@ -57,7 +72,7 @@ initProject target branch = do
5772 , "--no-preserve=mode"
5873 , "-T"
5974 , skeleton </> "."
60− , target
75+ , "."
6176 ] Nothing Nothing
6277 ExitSuccess <- waitForProcess p
6378 return ()