-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsysinfo.ml
39 lines (36 loc) · 1010 Bytes
/
sysinfo.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
open Sysinfo
let run_cmd cmd =
match cmd with
| "packages" ->
Packages.get ()
|> List.filter_map Result.to_option
|> List.iter (fun r ->
r |> Packages.to_yojson |> Yojson.Safe.pretty_to_string |> print_endline)
| "processes" ->
Processes.get ()
|> List.filter_map Result.to_option
|> List.iter (fun r ->
r |> Processes.to_yojson |> Yojson.Safe.pretty_to_string |> print_endline)
| "services" ->
Services.get ()
|> List.filter_map Result.to_option
|> List.iter (fun r ->
r |> Services.to_yojson |> Yojson.Safe.pretty_to_string |> print_endline)
| _ ->
print_endline "Invalid command";
()
;;
(**
Parse argv and select the appropriate function to call from:
- packages -> list all packages
- processes -> list all processes
*)
let parse_args () =
let usage = "Usage: sysinfo [packages|processes]" in
match Array.length Sys.argv with
| 2 -> run_cmd Sys.argv.(1)
| _ ->
print_endline usage;
()
;;
let () = parse_args ()