Skip to content

Commit

Permalink
Fixes #11: Don't throw in nonexistent directory on fnm ls + run `es…
Browse files Browse the repository at this point in the history
…y fmt` on codebase
  • Loading branch information
Schniz committed Jan 29, 2019
1 parent 01c16c3 commit fc85fee
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 11 deletions.
2 changes: 1 addition & 1 deletion executable/Env.re
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let run = isFishShell => {
Console.log(
Printf.sprintf("export PATH=%s/bin:$PATH", Directories.currentVersion),
);
}
};

Lwt.return();
};
6 changes: 2 additions & 4 deletions executable/FnmApp.re
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,7 @@ let env = {

let isFishShell = {
let doc = "Output an env configuration for fish shell.";
Arg.(
value & flag & info(["fish"], ~doc)
);
Arg.(value & flag & info(["fish"], ~doc));
};

(
Expand Down Expand Up @@ -122,4 +120,4 @@ let defaultCmd = {

let _ =
Term.eval_choice(defaultCmd, [install, use, listLocal, listRemote, env])
|> Term.exit;
|> Term.exit;
15 changes: 13 additions & 2 deletions executable/ListLocal.re
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
open Fnm;

let run = () =>
exception Cant_read_local_versions;

let main = () =>
Versions.Local.(
{
let%lwt versions = Versions.getInstalledVersions() |> Result.toLwt;
let%lwt versions =
Versions.getInstalledVersions()
|> Result.mapError(_ => Cant_read_local_versions)
|> Result.toLwtErr;
let currentVersion = Versions.getCurrentVersion();

Console.log("The following versions are installed:");
Expand All @@ -22,3 +27,9 @@ let run = () =>
Lwt.return();
}
);

let run = () =>
try%lwt (main()) {
| Cant_read_local_versions =>
Console.log("No versions installed!") |> Lwt.return
};
6 changes: 6 additions & 0 deletions feature_tests/list_local_with_nothing_installed/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

set -e

eval $(fnm env)
fnm ls
2 changes: 1 addition & 1 deletion library/Http.re
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ let download = (url, ~into) => {
~args=[|url, "-D", "-", "--silent", "-o", into|],
);
response |> parseResponse |> verifyStatus;
};
};
6 changes: 6 additions & 0 deletions library/Result.re
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,9 @@ let toLwt = res =>
| Error(x) => Lwt.fail_with(x)
| Ok(x) => Lwt.return(x)
};

let toLwtErr = res =>
switch (res) {
| Error(x) => Lwt.fail(x)
| Ok(x) => Lwt.return(x)
};
2 changes: 1 addition & 1 deletion library/Versions.re
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,4 @@ let getRemoteVersions = () => {
}
)
|> Lwt.return;
};
};
2 changes: 1 addition & 1 deletion test/SmokeTest.re
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ describe("Smoke test", ({test}) => {
let env = run([|"env"|]) |> redactSfwRoot;
expect.string(env).toMatchSnapshot();
});
});
});
2 changes: 1 addition & 1 deletion test/TestFnm.re
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
include SmokeTest;

TestFramework.cli();
TestFramework.cli();

0 comments on commit fc85fee

Please sign in to comment.