-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathWorld.hs
More file actions
62 lines (53 loc) · 1.75 KB
/
Copy pathWorld.hs
File metadata and controls
62 lines (53 loc) · 1.75 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
module CommandLine.World where
import Prelude ()
import Relude hiding (getLine, putStr)
data FileType
= IsFile
| IsDirectory
| DoesNotExist
class Monad m => World m where
readUtf8File :: FilePath -> m Text
readUtf8FileWithPath :: FilePath -> m (FilePath, Text)
readUtf8FileWithPath filePath =
(,) filePath <$> readUtf8File filePath
writeUtf8File :: FilePath -> Text -> m ()
writeUtf8FileNoOverwrite :: FilePath -> Text -> m ()
writeUtf8FileNoOverwrite path content =
do
exists <- doesFileExist path
case exists of
True ->
error "file exists and was not marked to be overwritten"
False ->
writeUtf8File path content
doesFileExist :: FilePath -> m Bool
doesDirectoryExist :: FilePath -> m Bool
listDirectory :: FilePath -> m [FilePath]
stat :: FilePath -> m FileType
stat path =
do
isFile <- doesFileExist path
isDirectory <- doesDirectoryExist path
return $ case ( isFile, isDirectory ) of
( True, _ ) -> IsFile
( _, True ) -> IsDirectory
( False, False ) -> DoesNotExist
getProgName :: m Text
getStdin :: m Text
getLine :: m Text
getYesOrNo :: m Bool
getYesOrNo =
do flushStdout
input <- getLine
case input of
"y" -> return True
"n" -> return False
_ -> putStr "Must type 'y' for yes or 'n' for no: " *> getYesOrNo
putStr :: Text -> m ()
putStrLn :: Text -> m ()
writeStdout :: Text -> m ()
flushStdout :: m ()
putStrStderr :: Text -> m ()
putStrLnStderr :: Text -> m()
exitFailure :: m ()
exitSuccess :: m ()