Skip to content

Commit 918bb54

Browse files
Add Process.setWorkingDir and IO.openFile (and constructors) (#79)
* add `Process.setWorkingDir` * add `IO.fileOpen` and datatypes
1 parent 0542596 commit 918bb54

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

examples/09-processes.hell

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,7 @@ main = do
1414

1515
let config = Process.proc "false" []
1616
code <- Process.runProcess config
17+
18+
Process.runProcess $ Process.setWorkingDir "/etc/" $ Process.proc "pwd" []
19+
1720
Text.putStrLn "Done."

examples/31-open-file-handle.hell

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
main = do
2+
let filepath = "out.txt"
3+
handle <- IO.openFile filepath IO.WriteMode
4+
let proc = Process.setStdout (Process.useHandleClose handle) $
5+
Process.proc "ls" ["-al"]
6+
Process.runProcess_ proc
7+
IO.hClose handle
8+
9+
contents <- Text.readFile filepath
10+
Text.putStrLn contents

src/Hell.hs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,6 +1229,11 @@ supportedLits =
12291229
("IO.LineBuffering", lit' IO.LineBuffering),
12301230
("IO.BlockBuffering", lit' IO.BlockBuffering),
12311231
("IO.hClose", lit' IO.hClose),
1232+
("IO.openFile", lit' (\f m -> IO.openFile (Text.unpack f) m)),
1233+
("IO.ReadMode", lit' IO.ReadMode),
1234+
("IO.WriteMode", lit' IO.WriteMode),
1235+
("IO.AppendMode", lit' IO.AppendMode),
1236+
("IO.ReadWriteMode", lit' IO.ReadWriteMode),
12321237
-- Concurrent stuff
12331238
("Concurrent.threadDelay", lit' Concurrent.threadDelay),
12341239
-- Bool
@@ -1600,8 +1605,9 @@ polyLits =
16001605
"Process.runProcess" runProcess :: forall a b c. ProcessConfig a b c -> IO ExitCode
16011606
"Process.runProcess_" runProcess_ :: forall a b c. ProcessConfig a b c -> IO ()
16021607
"Process.setStdout" setStdout :: forall stdin stdout stdout' stderr. StreamSpec 'STOutput stdout' -> ProcessConfig stdin stdout stderr -> ProcessConfig stdin stdout' stderr
1603-
"Process.useHandleClose" useHandleClose :: forall (a :: StreamType). IO.Handle -> StreamSpec a ()
1604-
"Process.useHandleOpen" useHandleOpen :: forall (a :: StreamType). IO.Handle -> StreamSpec a ()
1608+
"Process.useHandleClose" useHandleClose :: forall (a :: StreamType). IO.Handle -> StreamSpec a ()
1609+
"Process.useHandleOpen" useHandleOpen :: forall (a :: StreamType). IO.Handle -> StreamSpec a ()
1610+
"Process.setWorkingDir" process_setWorkingDir :: forall a b c. Text -> ProcessConfig a b c -> ProcessConfig a b c
16051611
|]
16061612
)
16071613

@@ -1770,6 +1776,12 @@ temp_withSystemTempFile template action = Temp.withSystemTempFile (Text.unpack t
17701776
temp_withSystemTempDirectory :: forall a. Text -> (Text -> IO a) -> IO a
17711777
temp_withSystemTempDirectory template action = Temp.withSystemTempDirectory (Text.unpack template) $ \fp -> action (Text.pack fp)
17721778

1779+
--------------------------------------------------------------------------------
1780+
-- Process operations
1781+
1782+
process_setWorkingDir :: forall a b c. Text -> ProcessConfig a b c -> ProcessConfig a b c
1783+
process_setWorkingDir filepath = Process.setWorkingDir (Text.unpack filepath)
1784+
17731785
--------------------------------------------------------------------------------
17741786
-- Inference type representation
17751787

0 commit comments

Comments
 (0)