@@ -22,6 +22,7 @@ import System.IO
2222import System.Posix.Process
2323
2424import Obelisk.Command.Project
25+import Obelisk.Command.Deploy
2526import Obelisk.Command.Thunk
2627import Obelisk.Command.Repl
2728import Obelisk.Command.Run
@@ -59,6 +60,7 @@ initSource = foldl1 (<|>)
5960
6061data ObCommand
6162 = ObCommand_Init InitSource
63+ | ObCommand_Deploy DeployCommand
6264 | ObCommand_Run
6365 | ObCommand_Thunk ThunkCommand
6466 | ObCommand_Repl FilePath
@@ -82,6 +84,7 @@ obCommand :: Parser ObCommand
8284obCommand = hsubparser
8385 (mconcat
8486 [ command "init" $ info (ObCommand_Init <$> initSource) $ progDesc "Initialize an Obelisk project"
87+ , command "deploy" $ info (ObCommand_Deploy <$> deployCommand) $ progDesc "Prepare a deployment for an Obelisk project"
8588 , command "run" $ info (pure ObCommand_Run) $ progDesc "Run current project in development mode"
8689 , command "thunk" $ info (ObCommand_Thunk <$> thunkCommand) $ progDesc "Manipulate thunk directories"
8790 , command "repl" $ info (ObCommand_Repl <$> (strArgument (action "directory"))) $ progDesc "Open an interactive interpreter"
@@ -93,6 +96,28 @@ obCommand = hsubparser
9396 , command "internal" (info (ObCommand_Internal <$> internalCommand) mempty)
9497 ])
9598
99+deployCommand :: Parser DeployCommand
100+deployCommand = hsubparser $ mconcat
101+ [ command "init" $ info deployInitCommand $ progDesc "Initialize a deployment configuration directory"
102+ ]
103+
104+deployInitCommand :: Parser DeployCommand
105+deployInitCommand = fmap DeployCommand_Init $ DeployInitOpts
106+ <$> strArgument (action "deploy-dir" <> metavar "DEPLOYDIR" <> help "Path to a directory that it will create")
107+ <*> strOption (long "ssh-key" <> metavar "SSHKEY" <> help "Path to an ssh key that it will symlink to")
108+ <*> some (strOption (long "hostname" <> metavar "HOSTNAME" <> help "hostname of the deployment target"))
109+ <*> strOption (long "remote" <> metavar "REMOTE" <> help "git remote to use for the src thunk")
110+
111+data DeployCommand
112+ = DeployCommand_Init DeployInitOpts
113+
114+data DeployInitOpts = DeployInitOpts
115+ { _deployInitOpts_ouputDir :: FilePath
116+ , _deployInitOpts_sshKey :: FilePath
117+ , _deployInitOpts_hostname :: [String]
118+ , _deployInitOpts_remote :: String
119+ }
120+
96121internalCommand :: Parser ObInternal
97122internalCommand = subparser $ mconcat
98123 [ command "run-static-io" $ info (ObInternal_RunStaticIO <$> argument (eitherReader decodeStaticKey) (action "static-key")) mempty
@@ -167,6 +192,13 @@ main = do
167192ob :: ObCommand -> IO ()
168193ob = \case
169194 ObCommand_Init source -> initProject source
195+ ObCommand_Deploy dc -> case dc of
196+ DeployCommand_Init deployOpts -> withProjectRoot "." $ \root -> do
197+ thunkPtr <- getThunkPtr root (_deployInitOpts_remote deployOpts)
198+ let deployDir = _deployInitOpts_ouputDir deployOpts
199+ sshKeyPath = _deployInitOpts_sshKey deployOpts
200+ hostname = _deployInitOpts_hostname deployOpts
201+ deployInit thunkPtr (root </> "config") deployDir sshKeyPath hostname
170202 ObCommand_Run -> inNixShell' $ static run
171203 -- inNixShell ($(mkClosure 'ghcidAction) ())
172204 ObCommand_Thunk tc -> case tc of