From d2bc9aa162afd696001dd4fe777e6bfc74487762 Mon Sep 17 00:00:00 2001 From: Ulrik Date: Mon, 5 Oct 2020 07:42:04 +0200 Subject: [PATCH] Start using reenv to add dotenv functionality --- bin/dune | 2 +- bin/main.ml | 19 ++++++-- esy.lock/index.json | 72 ++++++++++++++++++++++++++-- esy.lock/opam/merlin-extend.0.6/opam | 30 ++++++++++++ package.json | 6 ++- 5 files changed, 119 insertions(+), 10 deletions(-) create mode 100644 esy.lock/opam/merlin-extend.0.6/opam diff --git a/bin/dune b/bin/dune index 89d9769..afca784 100644 --- a/bin/dune +++ b/bin/dune @@ -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)) diff --git a/bin/main.ml b/bin/main.ml index 2abbdc7..92359d9 100644 --- a/bin/main.ml +++ b/bin/main.ml @@ -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 @@ -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) @@ -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 diff --git a/esy.lock/index.json b/esy.lock/index.json index b8287ff..8227c44 100644 --- a/esy.lock/index.json +++ b/esy.lock/index.json @@ -1,5 +1,5 @@ { - "checksum": "1638738e55c6c0fdf2ce648fa99315ae", + "checksum": "1dd9b20f8bd1bc3f0c9afaffdc845695", "root": "redemon@link-dev:./package.json", "node": { "yarn-pkg-config@github:esy-ocaml/yarn-pkg-config#db3a0b63883606dd57c54a7158d560d6cba8cd79@d41d8cd9": { @@ -29,9 +29,9 @@ }, "overrides": [], "dependencies": [ - "ocaml@4.10.0@d41d8cd9", "@opam/luv@opam:0.5.4@a3475408", - "@opam/logs@opam:0.7.0@1d03143e", "@opam/fmt@opam:0.8.8@01c3a23c", - "@opam/dune@opam:2.6.2@20433b4f", + "ocaml@4.10.0@d41d8cd9", "@opam/reenv@link:../reenv/package.json", + "@opam/luv@opam:0.5.4@a3475408", "@opam/logs@opam:0.7.0@1d03143e", + "@opam/fmt@opam:0.8.8@01c3a23c", "@opam/dune@opam:2.6.2@20433b4f", "@opam/cmdliner@opam:1.0.4@93208aac" ], "devDependencies": [ @@ -364,6 +364,24 @@ "ocaml@4.10.0@d41d8cd9", "@opam/dune@opam:2.6.2@20433b4f" ] }, + "@opam/reenv@link:../reenv/package.json": { + "id": "@opam/reenv@link:../reenv/package.json", + "name": "@opam/reenv", + "version": "link:../reenv/package.json", + "source": { + "type": "link", + "path": "../reenv", + "manifest": "package.json" + }, + "overrides": [], + "dependencies": [ + "ocaml@4.10.0@d41d8cd9", "@opam/re@opam:1.9.0@d4d5e13d", + "@opam/dune@opam:2.6.2@20433b4f", + "@opam/cmdliner@opam:1.0.4@93208aac", + "@esy-ocaml/reason@3.6.0@d41d8cd9" + ], + "devDependencies": [] + }, "@opam/re@opam:1.9.0@d4d5e13d": { "id": "@opam/re@opam:1.9.0@d4d5e13d", "name": "@opam/re", @@ -695,6 +713,31 @@ "@opam/dune@opam:2.6.2@20433b4f" ] }, + "@opam/merlin-extend@opam:0.6@404f814c": { + "id": "@opam/merlin-extend@opam:0.6@404f814c", + "name": "@opam/merlin-extend", + "version": "opam:0.6", + "source": { + "type": "install", + "source": [ + "archive:https://opam.ocaml.org/cache/sha256/c2/c2f236ae97feb6ba0bc90f33beb7b7343e42f9871b66de9ba07974917e256c43#sha256:c2f236ae97feb6ba0bc90f33beb7b7343e42f9871b66de9ba07974917e256c43", + "archive:https://github.com/let-def/merlin-extend/releases/download/v0.6/merlin-extend-v0.6.tbz#sha256:c2f236ae97feb6ba0bc90f33beb7b7343e42f9871b66de9ba07974917e256c43" + ], + "opam": { + "name": "merlin-extend", + "version": "0.6", + "path": "esy.lock/opam/merlin-extend.0.6" + } + }, + "overrides": [], + "dependencies": [ + "ocaml@4.10.0@d41d8cd9", "@opam/dune@opam:2.6.2@20433b4f", + "@opam/cppo@opam:1.6.6@f4f83858", "@esy-ocaml/substs@0.0.1@d41d8cd9" + ], + "devDependencies": [ + "ocaml@4.10.0@d41d8cd9", "@opam/dune@opam:2.6.2@20433b4f" + ] + }, "@opam/menhirSdk@opam:20200624@2a05b5a7": { "id": "@opam/menhirSdk@opam:20200624@2a05b5a7", "name": "@opam/menhirSdk", @@ -1327,6 +1370,27 @@ "overrides": [], "dependencies": [], "devDependencies": [] + }, + "@esy-ocaml/reason@3.6.0@d41d8cd9": { + "id": "@esy-ocaml/reason@3.6.0@d41d8cd9", + "name": "@esy-ocaml/reason", + "version": "3.6.0", + "source": { + "type": "install", + "source": [ + "archive:https://registry.npmjs.org/@esy-ocaml/reason/-/reason-3.6.0.tgz#sha1:ae98f3335e9e03ff0e01376830a14cd1246b5278" + ] + }, + "overrides": [], + "dependencies": [ + "ocaml@4.10.0@d41d8cd9", "@opam/result@opam:1.5@6b753c82", + "@opam/ocamlfind@opam:1.8.1@ff07b0f9", + "@opam/ocaml-migrate-parsetree@opam:1.7.3@dbcf3b47", + "@opam/merlin-extend@opam:0.6@404f814c", + "@opam/menhir@opam:20200624@8629ff13", + "@opam/fix@opam:20200131@0ecd2f01", "@opam/dune@opam:2.6.2@20433b4f" + ], + "devDependencies": [] } } } \ No newline at end of file diff --git a/esy.lock/opam/merlin-extend.0.6/opam b/esy.lock/opam/merlin-extend.0.6/opam new file mode 100644 index 0000000..39b3375 --- /dev/null +++ b/esy.lock/opam/merlin-extend.0.6/opam @@ -0,0 +1,30 @@ +opam-version: "2.0" +maintainer: "Frederic Bour " +authors: "Frederic Bour " +homepage: "https://github.com/let-def/merlin-extend" +bug-reports: "https://github.com/let-def/merlin-extend" +license: "MIT" +dev-repo: "git+https://github.com/let-def/merlin-extend.git" +build: [ + ["dune" "subst"] {pinned} + ["dune" "build" "-p" name "-j" jobs] +] +depends: [ + "dune" {>= "1.0"} + "cppo" {build} + "ocaml" {>= "4.02.3"} +] +synopsis: "A protocol to provide custom frontend to Merlin" +description: """ +This protocol allows to replace the OCaml frontend of Merlin. +It extends what used to be done with the `-pp' flag to handle a few more cases.""" +doc: "https://let-def.github.io/merlin-extend" +x-commit-hash: "640620568a5f5c7798239ecf7c707c813e3df3cf" +url { + src: + "https://github.com/let-def/merlin-extend/releases/download/v0.6/merlin-extend-v0.6.tbz" + checksum: [ + "sha256=c2f236ae97feb6ba0bc90f33beb7b7343e42f9871b66de9ba07974917e256c43" + "sha512=4c64a490e2ece04fc89aef679c1d9202175df4fe045b5fdc7a37cd7cebe861226fddd9648c1bf4f06175ecfcd2ed7686c96bd6a8cae003a5096f6134c240f857" + ] +} diff --git a/package.json b/package.json index a5b9fea..a767f96 100644 --- a/package.json +++ b/package.json @@ -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" } }