mirror of
https://git.sr.ht/~bryan_bennett/flake_env
synced 2025-12-16 06:31:24 +01:00
Simplify (and fix) direnv watch parsing
This commit is contained in:
parent
a26d9bbb17
commit
2b79807fce
1 changed files with 10 additions and 16 deletions
|
|
@ -15,22 +15,16 @@ type watches = array(watch);
|
|||
|
||||
let get = () => {
|
||||
let direnv_watch_str = Sys.getenv("DIRENV_WATCHES");
|
||||
|
||||
let (read_p, write_p) = Unix.pipe();
|
||||
let pid =
|
||||
Unix.create_process(
|
||||
"direnv",
|
||||
[|"direnv", "show_dump", direnv_watch_str|],
|
||||
Unix.stdin,
|
||||
write_p,
|
||||
Unix.stderr,
|
||||
);
|
||||
let sub_stdout = Unix.in_channel_of_descr(read_p);
|
||||
|
||||
switch (Unix.waitpid([], pid)) {
|
||||
| (reported_pid, WEXITED(0)) when reported_pid == pid =>
|
||||
Ok(watches_of_yojson(Yojson.Safe.from_channel(sub_stdout)))
|
||||
| _ => Error("Failed to parse watches")
|
||||
let stdout_read_ch =
|
||||
Unix.open_process_in("direnv show_dump " ++ direnv_watch_str);
|
||||
switch (Yojson.Safe.from_channel(stdout_read_ch)) {
|
||||
| exception (Yojson.Json_error(msg)) => Error(msg)
|
||||
| safe_t =>
|
||||
switch (watches_of_yojson(safe_t)) {
|
||||
| exception _ =>
|
||||
Error("Failed parsing watches; Has the direnv JSON shape changed?")
|
||||
| body => Ok(body)
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue