-
Notifications
You must be signed in to change notification settings - Fork 126
/
ChangeDir.hs
40 lines (32 loc) · 1.05 KB
/
ChangeDir.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{-# LANGUAGE OverloadedStrings #-}
module CryptolServer.ChangeDir
( cd
, cdDescr
, ChangeDirectoryParams(..)
) where
import qualified Argo.Doc as Doc
import Control.Monad.IO.Class
import Data.Aeson as JSON
import System.Directory
import CryptolServer
import CryptolServer.Exceptions
cdDescr :: Doc.Block
cdDescr = Doc.Paragraph
[Doc.Text "Changes the server's working directory to the given path."]
cd :: ChangeDirectoryParams -> CryptolMethod ()
cd (ChangeDirectoryParams newDir) =
do exists <- liftIO $ doesDirectoryExist newDir
if exists
then liftIO $ setCurrentDirectory newDir
else raise (dirNotFound newDir)
data ChangeDirectoryParams
= ChangeDirectoryParams FilePath
instance FromJSON ChangeDirectoryParams where
parseJSON =
withObject "params for \"change directory\"" $
\o -> ChangeDirectoryParams <$> o .: "directory"
instance Doc.DescribedParams ChangeDirectoryParams where
parameterFieldDescription =
[("directory",
Doc.Paragraph [Doc.Text "The path to change the current directory."])
]