Something went wrong. Try again.
My own corner of monopam
Something went wrong. Try again.
2.6 kB · 88 lines
OCaml
at main
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889let decode codec s = match Json.of_string codec s with | Ok v -> Ok v | Error e -> Error (Json.Error.to_string e)
let strings = let open Json.Codec in map ~dec:(function Some l -> l | None -> []) ~enc:(fun l -> Some l) (option (list string))
module Config = struct type t = { cmd : string list; tty : bool; attach_stdin : bool; attach_stdout : bool; attach_stderr : bool; }
let codec = let open Json.Codec in Object.map (fun cmd tty attach_stdin attach_stdout attach_stderr -> { cmd; tty; attach_stdin; attach_stdout; attach_stderr }) |> Object.member "Cmd" strings ~dec_absent:[] ~enc:(fun c -> c.cmd) |> Object.member "Tty" bool ~dec_absent:false ~enc:(fun c -> c.tty) |> Object.member "AttachStdin" bool ~dec_absent:false ~enc:(fun c -> c.attach_stdin) |> Object.member "AttachStdout" bool ~dec_absent:true ~enc:(fun c -> c.attach_stdout) |> Object.member "AttachStderr" bool ~dec_absent:true ~enc:(fun c -> c.attach_stderr) |> Object.skip_unknown |> Object.seal
let of_string s = decode codec s let to_string t = Json.to_string codec tend
module Create_response = struct type t = { id : string }
let codec = let open Json.Codec in Object.map (fun id -> { id }) |> Object.member "Id" string ~dec_absent:"" ~enc:(fun r -> r.id) |> Object.skip_unknown |> Object.seal
let of_string s = decode codec s let to_string t = Json.to_string codec tend
module Start = struct type t = { detach : bool; tty : bool }
let codec = let open Json.Codec in Object.map (fun detach tty -> { detach; tty }) |> Object.member "Detach" bool ~dec_absent:false ~enc:(fun s -> s.detach) |> Object.member "Tty" bool ~dec_absent:false ~enc:(fun s -> s.tty) |> Object.skip_unknown |> Object.seal
let of_string s = decode codec s let to_string t = Json.to_string codec tend
module Detail = struct type t = { id : string; running : bool; exit_code : int; container_id : string; }
let codec = let open Json.Codec in Object.map (fun id running exit_code container_id -> { id; running; exit_code; container_id }) |> Object.member "ID" string ~dec_absent:"" ~enc:(fun d -> d.id) |> Object.member "Running" bool ~dec_absent:false ~enc:(fun d -> d.running) |> Object.member "ExitCode" int ~dec_absent:0 ~enc:(fun d -> d.exit_code) |> Object.member "ContainerID" string ~dec_absent:"" ~enc:(fun d -> d.container_id) |> Object.skip_unknown |> Object.seal
let of_string s = decode codec s let to_string t = Json.to_string codec tend