Skip to content

Commit

Permalink
Add a --fnm-dir option to fnm env (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
Schniz authored Feb 18, 2019
1 parent 3bdfe02 commit 058916f
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion executable/Env.re
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let rec makeTemporarySymlink = () => {
};
};

let run = (~shell, ~multishell, ~nodeDistMirror) => {
let run = (~shell, ~multishell, ~nodeDistMirror, ~fnmDir) => {
open Lwt;

Random.self_init();
Expand All @@ -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,
Expand All @@ -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,
Expand Down
20 changes: 18 additions & 2 deletions executable/FnmApp.re
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
);
};
Expand Down Expand Up @@ -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),
);
};
Expand Down
1 change: 1 addition & 0 deletions test/__snapshots__/Smoke_test.4d362c3c.0.snapshot
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 058916f

Please sign in to comment.