Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Start using reenv to add dotenv functionality #11

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/dune
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
(executable
(public_name redemon)
(name main)
(libraries luv unix cmdliner logs logs.fmt fmt.tty))
(libraries luv unix cmdliner logs logs.fmt fmt.tty reenv))
19 changes: 15 additions & 4 deletions bin/main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,19 @@ let debounce delay fn =
| Ok () -> Logs.info (fun m -> m "Started timer, running in %ims" delay)
| Error _ -> Logs.err (fun m -> m "Error in timer") )

let redemon path paths extensions delay verbose command args =
let redemon path paths extensions envFiles delay verbose command args =
let () = init_logger verbose in
let extensions_provided = List.length extensions <> 0 in
let paths = path @ paths in
Logs.info (fun m -> m "Verbose mode enabled");
let child = ref (Error `UNKNOWN) in
let start_program () =
child := Luv.Process.spawn ~redirect command (command :: args)
let environment =
match envFiles with
| [] -> None
| _ -> Some Reenv.Env.(envFiles |> make |> to_tuple_list)
in
child := Luv.Process.spawn ?environment ~redirect command (command :: args)
in
let stop_program () =
Result.map (fun child -> Luv.Process.kill child Luv.Signal.sigkill) !child
Expand Down Expand Up @@ -126,6 +131,12 @@ let extensions =
Arg.(
value & opt (list string) [] & info [ "e"; "extensions" ] ~docv:"EXT" ~doc)

let envFiles =
let doc = "The .env files to read environment variables from, repeatable." in
Arg.(
value & opt_all non_dir_file []
& info [ "env"; "env-file" ] ~docv:"ENVFILE" ~doc)

let delay =
let doc = "Time in ms to wait before restarting" in
Arg.(value & opt int 100 & info [ "delay" ] ~docv:"DELAY" ~doc)
Expand All @@ -137,8 +148,8 @@ let verbose =
let _ =
let term =
Term.(
const redemon $ path $ paths $ extensions $ delay $ verbose $ command
$ args)
const redemon $ path $ paths $ extensions $ envFiles $ delay $ verbose
$ command $ args)
in
let doc = "A filewatcher built with luv" in
let info = Term.info ~doc "redemon" in
Expand Down
72 changes: 68 additions & 4 deletions esy.lock/index.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions esy.lock/opam/merlin-extend.0.6/opam

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,14 @@
"@opam/luv": "*",
"@opam/fmt": "*",
"@opam/logs": "*",
"ocaml": "^4.8.0"
"ocaml": "^4.8.0",
"@opam/reenv": "^1.0.0"
},
"devDependencies": {
"@opam/ocamlformat": "*",
"@opam/ocaml-lsp-server": "ocaml/ocaml-lsp:ocaml-lsp-server.opam"
},
"resolutions": {
"@opam/reenv": "link:../reenv/package.json"
}
}