@@ -1,10 +1,18 @@
11{-# LANGUAGE LambdaCase #-}
2+{-# LANGUAGE OverloadedStrings #-}
23module Obelisk.Command where
34
5+import Data.Monoid ((<>))
6+import Data.String (fromString)
7+import qualified Data.Text as Text
48import Options.Applicative
59import System.Environment
610import System.IO
711import System.Posix.Process
12+import System.Process
13+
14+import GitHub.Data.Name
15+import GitHub.Data.GitData
816
917import Obelisk.Command.Project
1018import Obelisk.Command.Thunk
@@ -34,15 +42,17 @@ argsInfo = info (args <**> helper) $ mconcat
3442 ]
3543
3644data ObCommand
37− = ObCommand_Init
45+ = ObCommand_Init (Name Branch)
3846 | ObCommand_Dev
3947 | ObCommand_Thunk ThunkCommand
48+ | ObCommand_Repl FilePath
4049
4150obCommand :: Parser ObCommand
4251obCommand = hsubparser $ mconcat
43− [ command "init" $ info (pure ObCommand_Init) $ progDesc "Initialize an Obelisk project"
52+ [ command "init" $ info (ObCommand_Init <$> (strArgument (value "master"))) $ progDesc "Initialize an Obelisk project"
4453 , command "dev" $ info (pure ObCommand_Dev) $ progDesc "Run the current project in development mode"
4554 , command "thunk" $ info (ObCommand_Thunk <$> thunkCommand) $ progDesc "Manipulate thunk directories"
55+ , command "repl" $ info (ObCommand_Repl <$> (strArgument (action "directory"))) $ progDesc "Open a cabal repl"
4656 ]
4757
4858data ThunkCommand
@@ -53,6 +63,15 @@ thunkCommand = hsubparser $ mconcat
5363 [ command "update" $ info (ThunkCommand_Update <$> some (strArgument (action "directory"))) $ progDesc "Update a thunk to the latest revision available"
5464 ]
5565
66+-- TODO modify the nix-shell arguments to recognize when the common dir's files have changed as well.
67+runRepl :: FilePath -> IO ()
68+runRepl dir = callProcess "nix-shell"
69+ [ "-A"
70+ , "shells.ghc"
71+ , "--run"
72+ , "\'cd " <> dir <> "; ghcid -W -c\"cabal new-repl exe:" <> dir <> "\""
73+ ]
74+
5675parserPrefs :: ParserPrefs
5776parserPrefs = defaultPrefs
5877 { prefShowHelpOnEmpty = True
@@ -83,9 +102,10 @@ main = do
83102
84103ob :: ObCommand -> IO ()
85104ob = \case
86− ObCommand_Init -> initProject "."
105+ ObCommand_Init branch -> initProject "." branch
87106 ObCommand_Dev -> putStrLn "Dev!"
88107 ObCommand_Thunk tc -> case tc of
89108 ThunkCommand_Update thunks -> mapM_ updateThunkToLatest thunks
109+ ObCommand_Repl component -> runRepl component
90110
91111--TODO: Clean up all the magic strings throughout this codebase