Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Process.setWorkingDir and IO.openFile (and constructors) #79

Merged
merged 2 commits into from
Jan 13, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/09-processes.hell
Original file line number Diff line number Diff line change
@@ -14,4 +14,7 @@ main = do

let config = Process.proc "false" []
code <- Process.runProcess config

Process.runProcess $ Process.setWorkingDir "/etc/" $ Process.proc "pwd" []

Text.putStrLn "Done."
10 changes: 10 additions & 0 deletions examples/31-open-file-handle.hell
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
main = do
let filepath = "out.txt"
handle <- IO.openFile filepath IO.WriteMode
let proc = Process.setStdout (Process.useHandleClose handle) $
Process.proc "ls" ["-al"]
Process.runProcess_ proc
IO.hClose handle

contents <- Text.readFile filepath
Text.putStrLn contents
16 changes: 14 additions & 2 deletions src/Hell.hs
Original file line number Diff line number Diff line change
@@ -1229,6 +1229,11 @@ supportedLits =
("IO.LineBuffering", lit' IO.LineBuffering),
("IO.BlockBuffering", lit' IO.BlockBuffering),
("IO.hClose", lit' IO.hClose),
("IO.openFile", lit' (\f m -> IO.openFile (Text.unpack f) m)),
("IO.ReadMode", lit' IO.ReadMode),
("IO.WriteMode", lit' IO.WriteMode),
("IO.AppendMode", lit' IO.AppendMode),
("IO.ReadWriteMode", lit' IO.ReadWriteMode),
-- Concurrent stuff
("Concurrent.threadDelay", lit' Concurrent.threadDelay),
-- Bool
@@ -1600,8 +1605,9 @@ polyLits =
"Process.runProcess" runProcess :: forall a b c. ProcessConfig a b c -> IO ExitCode
"Process.runProcess_" runProcess_ :: forall a b c. ProcessConfig a b c -> IO ()
"Process.setStdout" setStdout :: forall stdin stdout stdout' stderr. StreamSpec 'STOutput stdout' -> ProcessConfig stdin stdout stderr -> ProcessConfig stdin stdout' stderr
"Process.useHandleClose" useHandleClose :: forall (a :: StreamType). IO.Handle -> StreamSpec a ()
"Process.useHandleOpen" useHandleOpen :: forall (a :: StreamType). IO.Handle -> StreamSpec a ()
"Process.useHandleClose" useHandleClose :: forall (a :: StreamType). IO.Handle -> StreamSpec a ()
"Process.useHandleOpen" useHandleOpen :: forall (a :: StreamType). IO.Handle -> StreamSpec a ()
"Process.setWorkingDir" process_setWorkingDir :: forall a b c. Text -> ProcessConfig a b c -> ProcessConfig a b c
|]
)

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

--------------------------------------------------------------------------------
-- Process operations

process_setWorkingDir :: forall a b c. Text -> ProcessConfig a b c -> ProcessConfig a b c
process_setWorkingDir filepath = Process.setWorkingDir (Text.unpack filepath)

--------------------------------------------------------------------------------
-- Inference type representation