OCaml: Add debug logging tests
This commit is contained in:
parent
fab9c7140d
commit
f3557d5bb4
5 changed files with 39 additions and 7 deletions
|
|
@ -13,7 +13,7 @@ let interpret (past : Schema.schema) (input : string list) : Schema.schema =
|
|||
*)
|
||||
match input with
|
||||
| "pkg" :: tail -> System.Package.merge past tail
|
||||
| "os" :: _ -> say (System.File.read "/etc/os-release")
|
||||
| "os" :: _ -> say System.Os.identify
|
||||
| "user" :: _ -> say (System.Process.Reader.read [||] "whoami").output
|
||||
| "echo" :: tail -> say (String.concat " " tail)
|
||||
| ("version" | "-v" | "--version") :: _ ->
|
||||
|
|
|
|||
10
ocaml/lib/system/os.ml
Normal file
10
ocaml/lib/system/os.ml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
(* the side effect could be extracted to a log list in the schema *)
|
||||
let identify : string =
|
||||
let os_release = String.split_on_char '\n' (File.read "/etc/os-release") in
|
||||
Utilities.Log.elog (String.concat "\n" os_release);
|
||||
|
||||
let os_equals = List.find (String.starts_with ~prefix:"NAME=") os_release in
|
||||
match String.split_on_char '=' os_equals with
|
||||
| [ _; s ] ->
|
||||
String.trim @@ String.map (fun c -> if c = '"' then ' ' else c) s
|
||||
| _ -> "Unknown"
|
||||
Loading…
Add table
Add a link
Reference in a new issue