@@ -7,8 +7,10 @@ module Obelisk.Command.Project
7 , findProjectObeliskCommand
7 , findProjectObeliskCommand
8 , findProjectRoot
8 , findProjectRoot
9 , withProjectRoot
9 , withProjectRoot
10 , inProjectShell
11 , inProjectShell
11 , inImpureProjectShell
12 , inImpureProjectShell
12 , projectShell
14 , projectShell
14 , toObeliskDir
16 , toObeliskDir
@@ -18,6 +20,7 @@ module Obelisk.Command.Project
18import Control.Monad
20import Control.Monad
19import Control.Monad.IO.Class (liftIO)
21import Control.Monad.IO.Class (liftIO)
20import Control.Monad.State
22import Control.Monad.State
23+import qualified Data.ByteString.UTF8 as BSU
21import Data.Bits
24import Data.Bits
22import Data.Function (on)
25import Data.Function (on)
23import qualified Data.Text as T
26import qualified Data.Text as T
@@ -27,6 +30,7 @@ import System.IO.Temp
27import System.Posix (FileStatus, UserID, deviceID, fileID, fileMode, fileOwner, getFileStatus, getRealUserID)
30import System.Posix (FileStatus, UserID, deviceID, fileID, fileMode, fileOwner, getFileStatus, getRealUserID)
28import System.Posix.Files
31import System.Posix.Files
29import System.Process (CreateProcess, cwd, proc, waitForProcess, delegate_ctlc)
32import System.Process (CreateProcess, cwd, proc, waitForProcess, delegate_ctlc)
33+import Text.ShellEscape (Bash, bytes)
31import GitHub.Data.GitData (Branch)
35import GitHub.Data.GitData (Branch)
32import GitHub.Data.Name (Name)
36import GitHub.Data.Name (Name)
@@ -193,6 +197,10 @@ walkToImplDir projectRoot myUid = do
193isWritableOnlyBy :: FileStatus -> UserID -> Bool
197isWritableOnlyBy :: FileStatus -> UserID -> Bool
194isWritableOnlyBy s uid = fileOwner s == uid && fileMode s .&. 0o22 == 0
198isWritableOnlyBy s uid = fileOwner s == uid && fileMode s .&. 0o22 == 0
200+inProjectProc :: MonadObelisk m => String -> [Bash] -> m ()
201+inProjectProc shellName command = withProjectRoot "." $ \root ->
202+ projectProc root True shellName (Just command)
196-- | Run a command in the given shell for the current project
204-- | Run a command in the given shell for the current project
197inProjectShell :: MonadObelisk m => String -> String -> m ()
205inProjectShell :: MonadObelisk m => String -> String -> m ()
198inProjectShell shellName command = withProjectRoot "." $ \root ->
206inProjectShell shellName command = withProjectRoot "." $ \root ->
@@ -202,6 +210,12 @@ inImpureProjectShell :: MonadObelisk m => String -> String -> m ()
202inImpureProjectShell shellName command = withProjectRoot "." $ \root ->
210inImpureProjectShell shellName command = withProjectRoot "." $ \root ->
203 projectShell root False shellName (Just command)
211 projectShell root False shellName (Just command)
213+projectProc :: MonadObelisk m => FilePath -> Bool -> String -> Maybe [Bash] -> m ()
214+projectProc root isPure shellName command =
215+ projectShell root isPure shellName $ commandToString <$> command
217+ commandToString = unwords . fmap (BSU.toString . bytes)
205projectShell :: MonadObelisk m => FilePath -> Bool -> String -> Maybe String -> m ()
219projectShell :: MonadObelisk m => FilePath -> Bool -> String -> Maybe String -> m ()
206projectShell root isPure shellName command = do
220projectShell root isPure shellName command = do
207 (_, _, _, ph) <- createProcess_ "runNixShellAttr" $ setCtlc $ setCwd (Just root) $ proc "nix-shell" $
221 (_, _, _, ph) <- createProcess_ "runNixShellAttr" $ setCtlc $ setCwd (Just root) $ proc "nix-shell" $
@@ -213,7 +227,7 @@ projectShell root isPure shellName command = do
213 , "shells." <> shellName
227 , "shells." <> shellName
214 ] <> case command of
228 ] <> case command of
215 Nothing -> []
229 Nothing -> []
216− Just c -> ["--run", c]
230+ Just c -> ["--run", c]
217 void $ liftIO $ waitForProcess ph
231 void $ liftIO $ waitForProcess ph
219setCtlc :: CreateProcess -> CreateProcess
233setCtlc :: CreateProcess -> CreateProcess