OCaml: Add noninteractive configuration key

This commit is contained in:
Juno Takano 2025-05-16 23:18:23 -03:00
commit 1f16024c9e
4 changed files with 28 additions and 4 deletions

View file

@ -30,6 +30,7 @@ let string_of_token (token: token): string =
| Key k -> (match k with
| SuCommand -> "[ KEY: su_command ]"
| SuCommandQuoted -> "[ KEY: su_command_quoted ]"
| Interactive -> " [ KEY: interactive ]"
| Unknown -> "[ UNKNOWN KEY ]")
| Equal -> "[ OP: equal ]"
| Value v -> "[ VAL: " ^ v ^ " ]"

View file

@ -38,6 +38,9 @@ let update config key (value: string): Schema.main =
| SuCommandQuoted ->
{ config with
Schema.su_command_quoted = parse_boolean key value }
| Interactive ->
{ config with
Schema.interactive = bool_of_string value }
| Unknown ->
elog ~context:Parsing $ "[c.parser.update] Dropped value: unknown key";
config

View file

@ -17,8 +17,12 @@ type os = Unknown | FreeBSD | Void | Alpine
type host = { os : os; name : string }
type default_bool = Default | true | false
type configuration_key = SuCommand | SuCommandQuoted | Unknown
type main = { su_command : string list; su_command_quoted: default_bool }
type configuration_key = SuCommand | SuCommandQuoted | Interactive | Unknown
type main = {
su_command : string list;
su_command_quoted: default_bool;
interactive: bool
}
type configuration = { main : main; }
type input = { configuration: configuration; }
@ -48,6 +52,7 @@ let origin : schema = {
main = {
su_command = [ "su"; "-c" ];
su_command_quoted = Default;
interactive = true;
};
};
};
@ -72,6 +77,7 @@ let string_of_key key =
match key with
| SuCommand -> "su_command"
| SuCommandQuoted -> "su_command_quoted"
| Interactive -> "interactive"
| Unknown -> "<unknown key>"
let string_of_default_bool (b: default_bool): string =

View file

@ -1,6 +1,20 @@
open Utilities.Aliases
type install = { interactive: string list; batch: string list }
type manager = { install: install }
type manager_table = { apk: manager }
let table: manager_table = {
apk = {
install = {
interactive = [ "apk"; "-i"; "add"; ];
batch = [ "apk"; "--no-interactive"; "add"; ];
}
}
}
let su = Process.Su.elevate_wrapped
let manager = table.apk
let merge (schema : Schema.schema) (packages : string list) : Schema.schema =
match packages with
@ -16,12 +30,12 @@ let merge (schema : Schema.schema) (packages : string list) : Schema.schema =
[
{
name = su_command;
arguments = su schema $ [ "apk"; "-i"; "add" ] @ packages;
arguments = su schema $ manager.install.interactive @ packages;
status = Unevaluated;
};
{
name = su_command;
arguments = su schema $ [ "apk"; "-i"; "del" ] @ packages;
arguments = su schema $ manager.install.interactive @ packages;
status = Unevaluated;
};
]