77 envs,
88 clear_envs,
99 exec_output!,
10+ exec_output_bytes!,
1011 exec!,
1112 exec_cmd!,
1213 exec_exit_code!,
@@ -25,12 +26,12 @@ Cmd := InternalCmd.Command
2526## # Call echo to print "hello world"
2627## Cmd.exec!("echo", ["hello world"])?
2728## ```
28- exec ! : Str , List Str => Result {} [ExecFailed Str I32 , FailedToGetExitCode Str IOErr ]
29+ exec ! : Str , List Str => Result {} [ExecFailed Str I32 , FailedToGetExitCode ({ command : Str , err : IOErr }) ]
2930exec ! = |cmd_name, arguments|
3031 exit_code =
3132 new(cmd_name)
3233 |> args(arguments)
33- |> exec_exit_code!?
34+ |> exec_exit_code!() ?
3435
3536 if exit_code == 0i32 then
3637 Ok ({})
@@ -48,15 +49,15 @@ exec! = |cmd_name, arguments|
4849## |> Cmd.env("RUST_BACKTRACE", "1")
4950## |> Cmd.exec_cmd!()?
5051## ```
51- exec_cmd ! : Cmd => Result {} [ExecCmdFailed Str I32 , FailedToGetExitCode Str IOErr ]
52+ exec_cmd ! : Cmd => Result {} [ExecCmdFailed ({ command : Str , exit_code : I32 }) , FailedToGetExitCode ({ command : Str , err : IOErr }) ]
5253exec_cmd ! = |@Cmd (cmd)|
5354 exit_code =
5455 exec_exit_code!(@Cmd (cmd))?
5556
5657 if exit_code == 0i32 then
5758 Ok ({})
5859 else
59- Err (ExecCmdFailed (to_str(cmd), exit_code))
60+ Err (ExecCmdFailed ({ command: to_str(cmd), exit_code } ))
6061
6162## Execute command and capture stdout, stderr and the exit code in [Output].
6263##
@@ -68,50 +69,52 @@ exec_output! : Cmd =>
6869 Result
6970 {stdout_utf8 : Str , stderr_utf8_lossy : Str }
7071 [
71- StdoutContainsInvalidUtf8 ({ cmd : Str , err: [BadUtf8 { index : U64 , problem : Str . Utf8Problem }]}),
72- NonZeroExitCode ({cmd : Str , exit_code: I32 , stdout_utf8_lossy: Str , stderr_utf8_lossy: Str }),
73- FailedToGetExitCode ({ cmd : Str , err : IOErr })
72+ StdoutContainsInvalidUtf8 ({ cmd_str : Str , err: [BadUtf8 { index : U64 , problem : Str . Utf8Problem }]}),
73+ NonZeroExitCode ({command : Str , exit_code: I32 , stdout_utf8_lossy: Str , stderr_utf8_lossy: Str }),
74+ FailedToGetExitCode ({ command : Str , err : IOErr })
7475 ]
7576exec_output ! = |@Cmd (cmd)|
7677 exec_res = Host . command_exec_output !(cmd )
7778
7879 when exec_res is
79- Ok ({stdout_bytes, stderr_bytes }) ->
80- stdout_utf8 = Str . from_utf8 (stdout_bytes ) ? |err| StdoutContainsInvalidUtf8 ({ cmd: to_str(cmd), err})
80+ Ok ({stderr_bytes, stdout_bytes }) ->
81+ stdout_utf8 = Str . from_utf8 (stdout_bytes ) ? |err| StdoutContainsInvalidUtf8 ({cmd_str: to_str(cmd), err}) #{ cmd: to_str(cmd), err})
8182 stderr_utf8_lossy = Str . from_utf8_lossy (stderr_bytes )
8283
8384 Ok ({stdout_utf8, stderr_utf8_lossy})
8485 Err (inside_res) ->
8586 when inside_res is
86- Ok ({exit_code, stdout_bytes, stderr_bytes }) ->
87- stdout_utf8_lossy = Str . from_utf8_lossy (stdout_bytes )
88- stderr_utf8_lossy = Str . from_utf8_lossy (stderr_bytes )
87+ Ok ({exit_code, stderr_bytes, stdout_bytes }) ->
88+ stdout_utf8_lossy = Str . from_utf8_lossy (stdout_bytes )
89+ stderr_utf8_lossy = Str . from_utf8_lossy (stderr_bytes )
8990
90- Err (NonZeroExitCode ({cmd : to_str(cmd), exit_code, stdout_utf8_lossy, stderr_utf8_lossy}))
91+ Err (NonZeroExitCode ({command : to_str(cmd), exit_code, stdout_utf8_lossy, stderr_utf8_lossy}))
9192 Err (err) ->
92- Err (InternalIOErr . handle_err (err ))
93- |> Result . map_err (|er | FailedToGetExitCode ({ cmd : to_str(cmd), err : er }))
93+ Err (FailedToGetExitCode ({ command : to_str(cmd), err : InternalIOErr . handle_err (err ) }))
9494
95- # TODO exec_output_bytes
95+ ## TODO add type + explain command + when to use exec_output! + example
96+ exec_output_bytes ! = |@Cmd (cmd)|
97+ exec_res = Host . command_exec_output !(cmd )
98+
99+ when exec_res is
100+ Ok ({stderr_bytes, stdout_bytes}) ->
101+ Ok ({stdout_bytes, stderr_bytes})
102+
103+ Err (inside_res) ->
104+ when inside_res is
105+ Ok ({exit_code, stderr_bytes, stdout_bytes}) ->
106+ Err (NonZeroExitCodeB ({exit_code, stdout_bytes, stderr_bytes}))
107+
108+ Err (err) ->
109+ Err (FailedToGetExitCodeB (InternalIOErr . handle_err (err )))
96110
97111## Execute command and inherit stdin, stdout and stderr from parent. Returns the exit code.
98112## Helper function.
99- exec_exit_code ! : Cmd => Result I32 [FailedToGetExitCode Str IOErr ]
113+ exec_exit_code ! : Cmd => Result I32 [FailedToGetExitCode ({ command : Str , err : IOErr }) ]
100114exec_exit_code ! = |@Cmd (cmd)|
101115 Host . command_exec_exit_code !(cmd )
102116 |> Result . map_err (InternalIOErr . handle_err )
103- |> Result . map_err (|err | FailedToGetExitCode (to_str(cmd), err))
104-
105- # This hits a compiler bug: Alias `6.IdentId(11)` not registered in delayed aliases! ...
106- # ## Converts output into a utf8 string. Invalid utf8 sequences in stderr are ignored.
107- # to_str : Output -> Result Str [BadUtf8 { index : U64, problem : Str.Utf8Problem }]
108- # to_str = |output|
109- # InternalCmd.output_to_str(output)
110-
111- # ## Converts output into a utf8 string, ignoring any invalid utf8 sequences.
112- # to_str_lossy : Output -> Str
113- # to_str_lossy = |output|
114- # InternalCmd.output_to_str_lossy(output)
117+ |> Result . map_err (|err | FailedToGetExitCode ({ command: to_str(cmd), err }))
115118
116119## Create a new command to execute the given program in a child process.
117120new : Str -> Cmd
0 commit comments