diff --git a/executable/Install.re b/executable/Install.re index 3c935e8..cc0b2dd 100644 --- a/executable/Install.re +++ b/executable/Install.re @@ -27,6 +27,7 @@ let main = (~version as versionName) => { }; let versionName = Versions.format(versionName); + let%lwt _ = Versions.throwIfInstalled(versionName); Console.log( diff --git a/library/Versions.re b/library/Versions.re index 100ad54..8f19926 100644 --- a/library/Versions.re +++ b/library/Versions.re @@ -8,6 +8,7 @@ module Local = { }; exception Version_not_found(string); +exception Already_installed(string); module Remote = { type t = { @@ -145,3 +146,15 @@ let getRemoteVersions = () => { ) |> Lwt.return; }; + +let throwIfInstalled = versionName => { + getInstalledVersions() + |> Result.fold( + _ => Lwt.return(), + xs => + Array.exists(x => Local.(x.name == versionName), xs) + |> ( + x => x ? Lwt.fail(Already_installed(versionName)) : Lwt.return() + ), + ); +};