From 058916f05e9efde9e7a369e897d1492cc001d5d6 Mon Sep 17 00:00:00 2001 From: Gal Schlezinger Date: Tue, 19 Feb 2019 00:39:11 +0200 Subject: [PATCH] Add a `--fnm-dir` option to `fnm env` (#49) --- README.md | 3 ++- executable/Env.re | 4 +++- executable/FnmApp.re | 20 +++++++++++++++++-- .../Smoke_test.4d362c3c.0.snapshot | 1 + 4 files changed, 24 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d1c8f62f8..221fec94c 100644 --- a/README.md +++ b/README.md @@ -64,13 +64,14 @@ Lists the installed Node versions. Lists the Node versions available to download remotely. -### `fnm env [--multi] [--fish] [--node-dist-mirror=URI]` +### `fnm env [--multi] [--fish] [--node-dist-mirror=URI] [--base-dir=DIR]` Prints the required shell commands in order to configure your shell, Bash compliant by default. - Providing `--multi` will output the multishell support, allowing a different current Node version per shell - Providing `--fish` will output the Fish-compliant version. - Providing `--node-dist-mirror="https://npm.taobao.org/dist"` will use the Chinese mirror of Node.js +- Providing `--base-dir="/tmp/fnm"` will install and use versions in `/tmp/fnm` directory ## Future Plans diff --git a/executable/Env.re b/executable/Env.re index 8e4195dfe..70fd3541a 100644 --- a/executable/Env.re +++ b/executable/Env.re @@ -29,7 +29,7 @@ let rec makeTemporarySymlink = () => { }; }; -let run = (~shell, ~multishell, ~nodeDistMirror) => { +let run = (~shell, ~multishell, ~nodeDistMirror, ~fnmDir) => { open Lwt; Random.self_init(); @@ -43,6 +43,7 @@ let run = (~shell, ~multishell, ~nodeDistMirror) => { Printf.sprintf("export PATH=%s/bin:$PATH", path) |> Console.log; Printf.sprintf("export %s=%s", Config.FNM_MULTISHELL_PATH.name, path) |> Console.log; + Printf.sprintf("export %s=%s", Config.FNM_DIR.name, fnmDir) |> Console.log; Printf.sprintf( "export %s=%s", Config.FNM_NODE_DIST_MIRROR.name, @@ -53,6 +54,7 @@ let run = (~shell, ~multishell, ~nodeDistMirror) => { Printf.sprintf("set PATH %s/bin $PATH;", path) |> Console.log; Printf.sprintf("set %s %s;", Config.FNM_MULTISHELL_PATH.name, path) |> Console.log; + Printf.sprintf("set %s %s;", Config.FNM_DIR.name, fnmDir) |> Console.log; Printf.sprintf( "set %s %s", Config.FNM_NODE_DIST_MIRROR.name, diff --git a/executable/FnmApp.re b/executable/FnmApp.re index 70a739ee2..62102fe55 100644 --- a/executable/FnmApp.re +++ b/executable/FnmApp.re @@ -6,12 +6,13 @@ module Commands = { let listRemote = () => Lwt_main.run(ListRemote.run()); let listLocal = () => Lwt_main.run(ListLocal.run()); let install = version => Lwt_main.run(Install.run(~version)); - let env = (isFishShell, isMultishell, nodeDistMirror) => + let env = (isFishShell, isMultishell, nodeDistMirror, fnmDir) => Lwt_main.run( Env.run( ~shell=Fnm.System.Shell.(isFishShell ? Fish : Bash), ~multishell=isMultishell, ~nodeDistMirror, + ~fnmDir, ), ); }; @@ -157,13 +158,28 @@ let env = { ); }; + let fnmDir = { + let doc = "The directory to store internal fnm data"; + Arg.( + value + & opt(string, Fnm.Config.FNM_DIR.get()) + & info(["fnm-dir"], ~doc) + ); + }; + let isMultishell = { let doc = "Allow different Node versions for each shell"; Arg.(value & flag & info(["multi"], ~doc)); }; ( - Term.(const(Commands.env) $ isFishShell $ isMultishell $ nodeDistMirror), + Term.( + const(Commands.env) + $ isFishShell + $ isMultishell + $ nodeDistMirror + $ fnmDir + ), Term.info("env", ~version, ~doc, ~exits=Term.default_exits, ~man, ~sdocs), ); }; diff --git a/test/__snapshots__/Smoke_test.4d362c3c.0.snapshot b/test/__snapshots__/Smoke_test.4d362c3c.0.snapshot index 4470bbc6f..879d6a8fa 100644 --- a/test/__snapshots__/Smoke_test.4d362c3c.0.snapshot +++ b/test/__snapshots__/Smoke_test.4d362c3c.0.snapshot @@ -1,5 +1,6 @@ Smoke test › env export PATH=/current/bin:$PATH export FNM_MULTISHELL_PATH=/current +export FNM_DIR=/ export FNM_NODE_DIST_MIRROR=https://nodejs.org/dist