Browse Source

Add a `--fnm-dir` option to `fnm env` (#49)

remotes/origin/add-simple-redirecting-site
Gal Schlezinger 6 years ago committed by GitHub
parent
commit
058916f05e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 3
      README.md
  2. 4
      executable/Env.re
  3. 20
      executable/FnmApp.re
  4. 1
      test/__snapshots__/Smoke_test.4d362c3c.0.snapshot

3
README.md

@ -64,13 +64,14 @@ Lists the installed Node versions. @@ -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

4
executable/Env.re

@ -29,7 +29,7 @@ let rec makeTemporarySymlink = () => { @@ -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) => { @@ -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) => { @@ -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,

20
executable/FnmApp.re

@ -6,12 +6,13 @@ module Commands = { @@ -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 = { @@ -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),
);
};

1
test/__snapshots__/Smoke_test.4d362c3c.0.snapshot

@ -1,5 +1,6 @@ @@ -1,5 +1,6 @@
Smoke test › env
export PATH=<sfwRoot>/current/bin:$PATH
export FNM_MULTISHELL_PATH=<sfwRoot>/current
export FNM_DIR=<sfwRoot>/
export FNM_NODE_DIST_MIRROR=https://nodejs.org/dist

Loading…
Cancel
Save