2016-11-03 16:44:09 +00:00
|
|
|
(** Simplified Async/Lwt like monad *)
|
|
|
|
|
2017-02-27 11:37:28 +00:00
|
|
|
open Import
|
|
|
|
|
2016-11-03 16:44:09 +00:00
|
|
|
type 'a t
|
|
|
|
|
|
|
|
val return : 'a -> 'a t
|
|
|
|
val (>>=) : 'a t -> ('a -> 'b t) -> 'b t
|
2016-12-02 13:54:32 +00:00
|
|
|
val (>>|) : 'a t -> ('a -> 'b) -> 'b t
|
|
|
|
|
|
|
|
val both : 'a t -> 'b t -> ('a * 'b) t
|
2016-11-03 16:44:09 +00:00
|
|
|
|
|
|
|
val all : 'a t list -> 'a list t
|
|
|
|
val all_unit : unit t list -> unit t
|
|
|
|
|
2016-12-07 15:55:47 +00:00
|
|
|
val with_exn_handler : (unit -> 'a) -> handler:(exn -> Printexc.raw_backtrace -> unit) -> 'a
|
|
|
|
|
2017-02-27 11:37:28 +00:00
|
|
|
(** How to handle sub-process failures *)
|
|
|
|
type ('a, 'b) failure_mode =
|
|
|
|
| Strict : ('a, 'a) failure_mode
|
|
|
|
(** Fail if the process exits with anything else than [0] *)
|
|
|
|
| Accept : int list -> ('a, ('a, int) result) failure_mode
|
|
|
|
(** Accept the following non-zero exit codes, and return [Error code] if the process
|
|
|
|
exists with one of these codes. *)
|
|
|
|
|
2017-02-27 14:15:30 +00:00
|
|
|
(** Where to redirect standard output *)
|
2017-03-13 08:10:33 +00:00
|
|
|
type std_output_to =
|
2017-02-27 14:15:30 +00:00
|
|
|
| Terminal
|
|
|
|
| File of string
|
|
|
|
| Opened_file of opened_file
|
|
|
|
|
|
|
|
and opened_file =
|
|
|
|
{ filename : string
|
|
|
|
; desc : opened_file_desc
|
|
|
|
; tail : bool
|
|
|
|
(** If [true], the descriptor is closed after starting the command *)
|
|
|
|
}
|
|
|
|
|
|
|
|
and opened_file_desc =
|
|
|
|
| Fd of Unix.file_descr
|
|
|
|
| Channel of out_channel
|
|
|
|
|
2016-12-02 13:54:32 +00:00
|
|
|
(** [run ?dir ?stdout_to prog args] spawns a sub-process and wait for its termination *)
|
|
|
|
val run
|
|
|
|
: ?dir:string
|
2017-03-13 08:10:33 +00:00
|
|
|
-> ?stdout_to:std_output_to
|
|
|
|
-> ?stderr_to:std_output_to
|
2016-12-02 13:54:32 +00:00
|
|
|
-> ?env:string array
|
2017-02-27 11:37:28 +00:00
|
|
|
-> (unit, 'a) failure_mode
|
2016-12-02 13:54:32 +00:00
|
|
|
-> string
|
|
|
|
-> string list
|
2017-02-27 11:37:28 +00:00
|
|
|
-> 'a t
|
2016-12-02 13:54:32 +00:00
|
|
|
|
|
|
|
(** Run a command and capture its output *)
|
|
|
|
val run_capture
|
|
|
|
: ?dir:string
|
|
|
|
-> ?env:string array
|
2017-02-27 11:37:28 +00:00
|
|
|
-> (string, 'a) failure_mode
|
2016-12-02 13:54:32 +00:00
|
|
|
-> string
|
|
|
|
-> string list
|
2017-02-27 11:37:28 +00:00
|
|
|
-> 'a t
|
2016-12-02 13:54:32 +00:00
|
|
|
val run_capture_line
|
|
|
|
: ?dir:string
|
|
|
|
-> ?env:string array
|
2017-02-27 11:37:28 +00:00
|
|
|
-> (string, 'a) failure_mode
|
2016-12-02 13:54:32 +00:00
|
|
|
-> string
|
|
|
|
-> string list
|
2017-02-27 11:37:28 +00:00
|
|
|
-> 'a t
|
2016-12-02 13:54:32 +00:00
|
|
|
val run_capture_lines
|
|
|
|
: ?dir:string
|
|
|
|
-> ?env:string array
|
2017-02-27 11:37:28 +00:00
|
|
|
-> (string list, 'a) failure_mode
|
2016-12-02 13:54:32 +00:00
|
|
|
-> string
|
|
|
|
-> string list
|
2017-02-27 11:37:28 +00:00
|
|
|
-> 'a t
|
2016-11-03 16:44:09 +00:00
|
|
|
|
|
|
|
module Scheduler : sig
|
2017-03-10 12:32:27 +00:00
|
|
|
val go : ?log:Log.t -> 'a t -> 'a
|
2017-03-07 10:14:16 +00:00
|
|
|
|
|
|
|
(** Executes [f] before exiting, after all pending commands have finished *)
|
|
|
|
val at_exit_after_waiting_for_commands : (unit -> unit) -> unit
|
2016-11-03 16:44:09 +00:00
|
|
|
end
|