From 1f16024c9ee9bd7ad86f9aaf4dae0139b5872227 Mon Sep 17 00:00:00 2001 From: jutty Date: Fri, 16 May 2025 23:18:23 -0300 Subject: [PATCH] OCaml: Add noninteractive configuration key --- ocaml/lib/parsers/config/lexer.ml | 1 + ocaml/lib/parsers/config/parser.ml | 3 +++ ocaml/lib/schema/schema.ml | 10 ++++++++-- ocaml/lib/system/package.ml | 18 ++++++++++++++++-- 4 files changed, 28 insertions(+), 4 deletions(-) diff --git a/ocaml/lib/parsers/config/lexer.ml b/ocaml/lib/parsers/config/lexer.ml index b4cc960..cc2e96f 100644 --- a/ocaml/lib/parsers/config/lexer.ml +++ b/ocaml/lib/parsers/config/lexer.ml @@ -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 ^ " ]" diff --git a/ocaml/lib/parsers/config/parser.ml b/ocaml/lib/parsers/config/parser.ml index 0e5cd4e..faebe97 100644 --- a/ocaml/lib/parsers/config/parser.ml +++ b/ocaml/lib/parsers/config/parser.ml @@ -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 diff --git a/ocaml/lib/schema/schema.ml b/ocaml/lib/schema/schema.ml index 818ef17..7b6329a 100644 --- a/ocaml/lib/schema/schema.ml +++ b/ocaml/lib/schema/schema.ml @@ -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 -> "" let string_of_default_bool (b: default_bool): string = diff --git a/ocaml/lib/system/package.ml b/ocaml/lib/system/package.ml index 0dac4e6..4e900d1 100644 --- a/ocaml/lib/system/package.ml +++ b/ocaml/lib/system/package.ml @@ -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; }; ]