OCaml: Add separate logging channels and a dedicated 'command' type

This commit is contained in:
Juno Takano 2025-04-13 22:12:44 -03:00
commit ac3dbe4d30
9 changed files with 72 additions and 36 deletions

View file

@ -1,15 +1,30 @@
let merge (schema: Schema.schema) (packages: string list) =
let merge (schema: Schema.schema) (packages: string list): Schema.schema =
match packages with
| [] -> { schema with output = { message = "No packages provided" } }
| [] -> { schema with output = {
schema.output with main = "No packages provided" }
}
| _ ->
let in_targets = List.flatten [["doas"; "apk"; "-i"; "add"]; packages] and
out_targets = List.flatten [["doas"; "apk"; "-i"; "del"]; packages] in
let commands: Process.Command.command list = [
{
name = "doas";
arguments = ["doas"; "apk"; "-i"; "add"] @ packages;
status = Unevaluated;
};
{
name = "doas";
arguments = ["doas"; "apk"; "-i"; "del"] @ packages;
status = Unevaluated;
}
] in
Process.Fork.run "doas" in_targets;
Process.Fork.run "doas" out_targets;
let ran = Process.Fork.run_many commands in
let formatted_ran = Process.Command.format_many ran in
{ schema with output = {
message = "Done: " ^ (String.concat "\n" packages)
}}
{
schema with output = {
schema.output with log =
"Done:\n" ^ (String.concat "\n" formatted_ran)
}
}