Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

skip installation if the version is already installed #27

Merged
merged 8 commits into from
Feb 14, 2019
Prev Previous commit
Next Next commit
add check func whether the specify version is already installed or not
  • Loading branch information
kentac55 committed Feb 11, 2019
commit c8079bf21a6a8b537132bc67c43cdbca7692df88
10 changes: 10 additions & 0 deletions executable/Install.re
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ let main = (~version as versionName) => {
};

let versionName = Versions.format(versionName);
let%lwt _ = Versions.isAlreadyInstalled(versionName);

Console.log(
<Pastel>
Expand Down Expand Up @@ -101,4 +102,13 @@ let run = (~version) =>
</Pastel>,
)
|> Lwt.return
| Versions.Already_installed(version) =>
Console.log(
<Pastel>
"Version "
<Pastel color=Pastel.Cyan> version </Pastel>
" is already installed"
</Pastel>,
)
|> Lwt.return
};
18 changes: 18 additions & 0 deletions library/Versions.re
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ module Local = {
};

exception Version_not_found(string);
exception Already_installed(string);

module Remote = {
type t = {
Expand Down Expand Up @@ -146,3 +147,20 @@ let getRemoteVersions = () => {
)
|> Lwt.return;
};

let isAlreadyInstalled = versionName => {
Schniz marked this conversation as resolved.
Show resolved Hide resolved
switch(getInstalledVersions()) {
Schniz marked this conversation as resolved.
Show resolved Hide resolved
| Ok(x) => {
Array.to_list(x)
|> List.exists(x => {
Schniz marked this conversation as resolved.
Show resolved Hide resolved
open Local;
Schniz marked this conversation as resolved.
Show resolved Hide resolved
x.name == versionName;
})
|> x => switch x {
Schniz marked this conversation as resolved.
Show resolved Hide resolved
| true => Lwt.fail(Already_installed(versionName));
| false => Lwt.return();
};
};
| Error(_) => Lwt.return();
Schniz marked this conversation as resolved.
Show resolved Hide resolved
};
};