@@ -20,10 +20,12 @@ import System.Posix.Process (executeFile)
21import Obelisk.Command.CLI (putErrorAndExit, putWarning, runCLI)
21import Obelisk.Command.CLI (putErrorAndExit, putWarning, runCLI)
22import Obelisk.Command.Deploy
22import Obelisk.Command.Deploy
23+import Obelisk.Command.Deploy
23import Obelisk.Command.Project
24import Obelisk.Command.Project
24import Obelisk.Command.Repl
25import Obelisk.Command.Repl
25import Obelisk.Command.Run
26import Obelisk.Command.Run
26import Obelisk.Command.Thunk
27import Obelisk.Command.Thunk
28+import Obelisk.Command.Utils
28data Args = Args
30data Args = Args
29 { _args_noHandOffPassed :: Bool
31 { _args_noHandOffPassed :: Bool
@@ -95,18 +97,28 @@ obCommand = hsubparser
97deployCommand :: Parser DeployCommand
99deployCommand :: Parser DeployCommand
98−deployCommand = subparser $ mconcat
100+deployCommand = hsubparser $ mconcat
99 [ command "init" $ info deployInitCommand $ progDesc "Initialize a deployment configuration directory"
101 [ command "init" $ info deployInitCommand $ progDesc "Initialize a deployment configuration directory"
102+ , command "push" $ info (pure DeployCommand_Push) mempty
102deployInitCommand :: Parser DeployCommand
105deployInitCommand :: Parser DeployCommand
103−deployInitCommand = DeployCommand_Init
106+deployInitCommand = fmap DeployCommand_Init $ DeployInitOpts
104− <$> strArgument (action "deploy-dir" <> metavar "DEPLOYDIR")
107+ <$> strArgument (action "deploy-dir" <> metavar "DEPLOYDIR" <> help "Path to a directory that it will create")
105− <*> strArgument (action "ssh-key" <> metavar "SSH_KEY")
108+ <*> strOption (long "ssh-key" <> metavar "SSHKEY" <> help "Path to an ssh key that it will symlink to")
106− <*> strArgument (action "hostname" <> metavar "HOSTNAME")
109+ <*> some (strOption (long "hostname" <> metavar "HOSTNAME" <> help "hostname of the deployment target"))
110+ <*> strOption (long "remote" <> metavar "REMOTE" <> help "git remote to use for the src thunk")
108data DeployCommand
112data DeployCommand
109− = DeployCommand_Init String String String
113+ = DeployCommand_Init DeployInitOpts
114+ | DeployCommand_Push
116+data DeployInitOpts = DeployInitOpts
117+ { _deployInitOpts_ouputDir :: FilePath
118+ , _deployInitOpts_sshKey :: FilePath
119+ , _deployInitOpts_hostname :: [String]
120+ , _deployInitOpts_remote :: String
111internalCommand :: Parser ObInternal
123internalCommand :: Parser ObInternal
112internalCommand = subparser $ mconcat
124internalCommand = subparser $ mconcat
@@ -183,8 +195,21 @@ ob :: ObCommand -> IO ()
183ob = \case
195ob = \case
184 ObCommand_Init source -> initProject source
196 ObCommand_Init source -> initProject source
185 ObCommand_Deploy dc -> case dc of
197 ObCommand_Deploy dc -> case dc of
186− DeployCommand_Init deployDir sshKeyPath hostname -> withProjectRoot "." $ \root ->
198+ DeployCommand_Init deployOpts -> withProjectRoot "." $ \root -> do
199+ thunkPtr <- readThunk root >>= \case
200+ Left err -> fail $ "thunk pack: " <> show err
201+ Right (ThunkData_Packed ptr) -> return ptr
202+ Right (ThunkData_Checkout (Just ptr)) -> return ptr
203+ Right (ThunkData_Checkout Nothing) ->
204+ getThunkPtr root (_deployInitOpts_remote deployOpts)
205+ let deployDir = _deployInitOpts_ouputDir deployOpts
206+ sshKeyPath = _deployInitOpts_sshKey deployOpts
207+ hostname = _deployInitOpts_hostname deployOpts
187− deployInit (root </> "config") deployDir sshKeyPath hostname
208+ deployInit thunkPtr (root </> "config") deployDir sshKeyPath hostname
209+ DeployCommand_Push -> do
210+ checkGitCleanStatus "." >>= \case
212+ False -> fail "ob push: Commit any changes to the deployment configuration before proceeding"
188 ObCommand_Run -> inNixShell' $ static run
213 ObCommand_Run -> inNixShell' $ static run
189 -- inNixShell ($(mkClosure 'ghcidAction) ())
214 -- inNixShell ($(mkClosure 'ghcidAction) ())
190 ObCommand_Thunk tc -> case tc of
215 ObCommand_Thunk tc -> case tc of