@@ -20,10 +20,12 @@ import System.Posix.Process (executeFile)
2020
2121import Obelisk.Command.CLI (putErrorAndExit, putWarning, runCLI)
2222import Obelisk.Command.Deploy
23+import Obelisk.Command.Deploy
2324import Obelisk.Command.Project
2425import Obelisk.Command.Repl
2526import Obelisk.Command.Run
2627import Obelisk.Command.Thunk
28+import Obelisk.Command.Utils
2729
2830data Args = Args
2931 { _args_noHandOffPassed :: Bool
@@ -95,18 +97,28 @@ obCommand = hsubparser
9597 ])
9698
9799deployCommand :: Parser DeployCommand
98−deployCommand = subparser $ mconcat
100+deployCommand = hsubparser $ mconcat
99101 [ command "init" $ info deployInitCommand $ progDesc "Initialize a deployment configuration directory"
102+ , command "push" $ info (pure DeployCommand_Push) mempty
100103 ]
101104
102105deployInitCommand :: Parser DeployCommand
103−deployInitCommand = DeployCommand_Init
104− <$> strArgument (action "deploy-dir" <> metavar "DEPLOYDIR")
105− <*> strArgument (action "ssh-key" <> metavar "SSH_KEY")
106− <*> strArgument (action "hostname" <> metavar "HOSTNAME")
106+deployInitCommand = fmap DeployCommand_Init $ DeployInitOpts
107+ <$> strArgument (action "deploy-dir" <> metavar "DEPLOYDIR" <> help "Path to a directory that it will create")
108+ <*> strOption (long "ssh-key" <> metavar "SSHKEY" <> help "Path to an ssh key that it will symlink to")
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")
107111
108112data DeployCommand
109− = DeployCommand_Init String String String
113+ = DeployCommand_Init DeployInitOpts
114+ | DeployCommand_Push
115+
116+data DeployInitOpts = DeployInitOpts
117+ { _deployInitOpts_ouputDir :: FilePath
118+ , _deployInitOpts_sshKey :: FilePath
119+ , _deployInitOpts_hostname :: [String]
120+ , _deployInitOpts_remote :: String
121+ }
110122
111123internalCommand :: Parser ObInternal
112124internalCommand = subparser $ mconcat
@@ -183,8 +195,21 @@ ob :: ObCommand -> IO ()
183195ob = \case
184196 ObCommand_Init source -> initProject source
185197 ObCommand_Deploy dc -> case dc of
186− DeployCommand_Init deployDir sshKeyPath hostname -> withProjectRoot "." $ \root ->
187− deployInit (root </> "config") deployDir sshKeyPath hostname
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
208+ deployInit thunkPtr (root </> "config") deployDir sshKeyPath hostname
209+ DeployCommand_Push -> do
210+ checkGitCleanStatus "." >>= \case
211+ True -> return ()
212+ False -> fail "ob push: Commit any changes to the deployment configuration before proceeding"
188213 ObCommand_Run -> inNixShell' $ static run
189214 -- inNixShell ($(mkClosure 'ghcidAction) ())
190215 ObCommand_Thunk tc -> case tc of