mirror of
https://git.sr.ht/~bryan_bennett/flake_env
synced 2025-12-16 14:41: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 get = () => {
|
||||||
let direnv_watch_str = Sys.getenv("DIRENV_WATCHES");
|
let direnv_watch_str = Sys.getenv("DIRENV_WATCHES");
|
||||||
|
let stdout_read_ch =
|
||||||
let (read_p, write_p) = Unix.pipe();
|
Unix.open_process_in("direnv show_dump " ++ direnv_watch_str);
|
||||||
let pid =
|
switch (Yojson.Safe.from_channel(stdout_read_ch)) {
|
||||||
Unix.create_process(
|
| exception (Yojson.Json_error(msg)) => Error(msg)
|
||||||
"direnv",
|
| safe_t =>
|
||||||
[|"direnv", "show_dump", direnv_watch_str|],
|
switch (watches_of_yojson(safe_t)) {
|
||||||
Unix.stdin,
|
| exception _ =>
|
||||||
write_p,
|
Error("Failed parsing watches; Has the direnv JSON shape changed?")
|
||||||
Unix.stderr,
|
| body => Ok(body)
|
||||||
);
|
}
|
||||||
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")
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue