Browse Source

Add `current` command to retrieve the current Node version (#220)

remotes/origin/add-simple-redirecting-site
Dario Vladović 5 years ago committed by GitHub
parent
commit
0a24f0dcd1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      README.md
  2. 11
      executable/Current.re
  3. 21
      executable/FnmApp.re
  4. 35
      feature_tests/current/run.sh

4
README.md

@ -88,6 +88,10 @@ Installs `[VERSION]`. If no version provided, it will install the version specif @@ -88,6 +88,10 @@ Installs `[VERSION]`. If no version provided, it will install the version specif
Activates `[VERSION]` as the current Node version. If no version provided, it will activate the version specified in the `.nvmrc` or `.node-version` file located in the current working directory.
### `fnm current`
Display currenty activated Node version.
### `fnm ls`
Lists the installed Node versions.

11
executable/Current.re

@ -0,0 +1,11 @@ @@ -0,0 +1,11 @@
open Fnm;
let run = () => {
let%lwt currentVersion = Versions.getCurrentVersion();
switch (currentVersion) {
| Some({name}) => Console.log(name)
| _ => Console.log("none")
};
Lwt.return_ok();
};

21
executable/FnmApp.re

@ -14,6 +14,7 @@ module Commands = { @@ -14,6 +14,7 @@ module Commands = {
let exec = (version, useFileVersion, cmd) =>
Exec.run(~cmd=Array.of_list(cmd), ~version, ~useFileVersion) |> runCmd;
let use = (version, quiet) => Use.run(~version, ~quiet) |> runCmd;
let current = () => Current.run() |> runCmd;
let alias = (version, name) => Alias.run(~name, ~version) |> runCmd;
let default = version => Alias.run(~name="default", ~version) |> runCmd;
let listRemote = version => ListRemote.run(~version) |> runCmd;
@ -200,6 +201,25 @@ let use = { @@ -200,6 +201,25 @@ let use = {
);
};
let current = {
let doc = "Display currently activated version";
let sdocs = Manpage.s_common_options;
let man = help_secs;
(
Term.(app(const(Commands.current), const())),
Term.info(
"current",
~envs,
~version,
~doc,
~exits=Term.default_exits,
~man,
~sdocs,
),
);
};
let alias = {
let doc = "Alias a version";
let sdocs = Manpage.s_common_options;
@ -417,6 +437,7 @@ let _ = @@ -417,6 +437,7 @@ let _ =
[
install,
uninstall,
current,
use,
alias,
default,

35
feature_tests/current/run.sh

@ -0,0 +1,35 @@ @@ -0,0 +1,35 @@
#!/bin/bash
set -e
PATH="$(pwd)":$PATH # simulating a custom `node`
eval "$(fnm env)"
if [ "$(fnm current)" != "none" ]; then
echo "Expected currently activated version is not none!"
exit 1
fi
fnm install v8.11.3
fnm install v10.10.0
fnm use v8.11.3
if [ "$(fnm current)" != "v8.11.3" ]; then
echo "Expected currently activated version is not v8.11.3!"
exit 1
fi
fnm use v10.10.0
if [ "$(fnm current)" != "v10.10.0" ]; then
echo "Expected currently activated version is not v10.10.0!"
exit 1
fi
fnm use system
if [ "$(fnm current)" != "system" ]; then
echo "Expected currently activated version is not system!"
exit 1
fi
Loading…
Cancel
Save