OCaml: Implement configuration parser, bind lexer tokens with schema

This commit is contained in:
Juno Takano 2025-05-08 23:10:14 -03:00
commit b0c65f40b1
12 changed files with 187 additions and 41 deletions

View file

@ -1,8 +1,11 @@
open Utilities.Aliases
type schema = Schema.schema
type status = Exit of int | Unevaluated
type command = { name : string; arguments : string list; status : status }
let format (command : command) : string =
command.name ^ " with arguments: "
^ String.concat " " command.arguments
@ -14,3 +17,22 @@ let format (command : command) : string =
let format_many (commands : command list) : string list =
List.map format commands
let check_su_command (schema: schema): schema =
let command = schema.input.configuration.main.su_command in
let path = Reader.read [||] ("which " ^ command) in
try Unix.access path.output [Unix.X_OK]; schema
with Unix.Unix_error _ -> elog "";
{
schema with
output =
{
schema.output with
main =
"Super user command " ^ command ^
" not executable at path '" ^ path.output ^
"' (exit status " ^ path.status ^ ", stderr: '" ^
path.error ^ "')\n"
};
meta = { schema.meta with status = 1 };
}