From b7ed348541a57b1fe0662cc23dd706b02e68d7ad Mon Sep 17 00:00:00 2001 From: Corentin Leruth Date: Mon, 9 Mar 2020 16:23:46 +0100 Subject: [PATCH] Create alias from version range (fix #185) (#201) Based on #194 to benefit from the `LocalVersionResolver` module. So I guess this PR should be merged first. This should fix #185 --- executable/Alias.re | 39 +++++++++++++++++++++------------------ 1 file changed, 21 insertions(+), 18 deletions(-) diff --git a/executable/Alias.re b/executable/Alias.re index 8484245..d631e52 100644 --- a/executable/Alias.re +++ b/executable/Alias.re @@ -2,33 +2,36 @@ open Fnm; let run = (~name, ~version) => { let version = Versions.format(version); - let versionPath = - Filename.concat( - Filename.concat(Directories.nodeVersions, version), - "installation", - ); - let%lwt versionInstalled = Lwt_unix.file_exists(versionPath); + let%lwt matchingLocalVersions = + LocalVersionResolver.getMatchingLocalVersions(version); - if (!versionInstalled) { - Logger.error( - - "Can't find a version installed in " - versionPath - , - ); - Lwt.return_error(1); - } else { + switch (Base.List.hd(matchingLocalVersions)) { + | Some(latestMatchingLocalVersion) => Logger.info( "Aliasing " name " to " - version + {latestMatchingLocalVersion.name} , ); - let%lwt () = Versions.Aliases.set(~alias=name, ~versionPath); - + let%lwt () = + Versions.Aliases.set( + ~alias=name, + ~versionPath= + Filename.concat( + latestMatchingLocalVersion.fullPath, + "installation", + ), + ); Lwt.return_ok(); + | None => + Logger.error( + + "No installed versions found that match your criteria." + , + ); + Lwt.return_error(1); }; };