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); }; };