struct
let exec l = Exec (List.map l ~f:(fun s -> Literal (Literal.String s)))
let call l = Exec l
let (&&&) a b = Bool_operator (a, `And, b)
let (|||) a b = Bool_operator (a, `Or, b)
let (=$=) a b = String_operator (a, `Eq, b)
let (<$>) a b = String_operator (a, `Neq, b)
let returns expr ~value = Returns {expr; value}
let succeeds expr = returns expr ~value:0
let nop = No_op
let if_then_else a b c = If (a, b, c)
let if_then a b = if_then_else a b nop
let seq l = Seq l
let not t = Not t
let with_signal ?(signal_name = "USR2") ~catch run =
With_signal {signal_name; catch; run}
let fail = Fail
let make_switch: type a. (bool t * unit t) list -> default: unit t -> unit t =
fun conds ~default ->
List.fold_right conds ~init:default ~f:(fun (x, body) prev ->
if_then_else x body prev)
let write_output ?stdout ?stderr ?return_value expr =
Write_output {expr; stdout; stderr; return_value}
let write_stdout ~path expr = write_output expr ~stdout:path
let to_fd take fd = { take; redirect_to = `Fd fd }
let to_file take file = { take; redirect_to = `Path file }
let with_redirections cmd l =
Redirect_output (cmd, l)
let literal l = Literal l
let string s = Literal.String s |> literal
let int s = Literal.Int s |> literal
let bool t = Literal.Bool t |> literal
let file_exists p =
call [string "test"; string "-f"; p] |> succeeds
let getenv v = Getenv v
let setenv ~var v = Setenv (var, v)
let output_as_string e = Output_as_string e
let feed ~string e = Feed (string, e)
let (>>) string e = feed ~string e
let pipe l = Pipe l
let (||>) a b = Pipe [a; b]
let loop_while condition ~body = While {condition; body}
let list l = List l
let string_concat_list l = String_concat l
let list_append la lb = List_append (la, lb)
let list_iter l ~f = List_iter (l, f)
let list_to_string l ~f = List_to_string (l, f)
let list_of_string l ~f = String_to_list (l, f)
module Bool = struct
let of_string s = String_to_bool s
let to_string b = Bool_to_string b
end
module Integer = struct
let to_string i = Int_to_string i
let of_string s = String_to_int s
let bin_op a o b = Int_bin_op (a, o, b)
let add a b = bin_op a `Plus b
let (+) = add
let sub a b = bin_op a `Minus b
let (-) = sub
let mul a b = bin_op a `Mult b
let ( * ) = mul
let div a b = bin_op a `Div b
let (/) = div
let modulo a b = bin_op a `Mod b
let (mod) = modulo
let cmp op a b = Int_bin_comparison (a, op, b)
let eq = cmp `Eq
let ne = cmp `Ne
let lt = cmp `Lt
let le = cmp `Le
let ge = cmp `Ge
let gt = cmp `Gt
let (=) = eq
let (<>) = ne
let (<) = lt
let (<=) = le
let (>=) = ge
let (>) = gt
end
module Magic = struct
let unit s : unit t = Raw_cmd s
end
end