Skip to content

Commit

Permalink
Introduce ability to use latest
Browse files Browse the repository at this point in the history
  • Loading branch information
simshaun committed Apr 5, 2022
1 parent 8ea9494 commit 830ef3b
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 16 deletions.
44 changes: 29 additions & 15 deletions NodeSwap/Commands/UseCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,26 +26,40 @@ public async Task<int> InvokeAsync(InvocationContext context)
return 1;
}

Version version;
try
NodeJsVersion nodeVersion;

if (rawVersion.ToString() == "latest")
{
version = VersionParser.StrictParse(rawVersion.ToString()!);
nodeVersion = _nodeLocal.GetLatestInstalledVersion();
if (nodeVersion == null)
{
await Console.Error.WriteLineAsync($"There are no versions installed");
return 1;
}
}
catch (ArgumentException)
else
{
await Console.Error.WriteLineAsync($"Invalid version argument: {rawVersion}");
return 1;
}
Version version;
try
{
version = VersionParser.StrictParse(rawVersion.ToString()!);
}
catch (ArgumentException)
{
await Console.Error.WriteLineAsync($"Invalid version argument: {rawVersion}");
return 1;
}

//
// Is the requested version installed?
//
//
// Is the requested version installed?
//

var nodeVersion = _nodeLocal.GetInstalledVersions().Find(v => v.Version.Equals(version));
if (nodeVersion == null)
{
await Console.Error.WriteLineAsync($"{version} not installed");
return 1;
nodeVersion = _nodeLocal.GetInstalledVersions().Find(v => v.Version.Equals(version));
if (nodeVersion == null)
{
await Console.Error.WriteLineAsync($"{version} not installed");
return 1;
}
}

//
Expand Down
7 changes: 7 additions & 0 deletions NodeSwap/NodeJs.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#nullable enable

using System;
using System.Collections.Generic;
using System.IO;
Expand All @@ -15,6 +17,11 @@ public NodeJs(GlobalContext globalContext)
_globalContext = globalContext;
}

public NodeJsVersion? GetLatestInstalledVersion()
{
return GetInstalledVersions().FirstOrDefault();
}

public List<NodeJsVersion> GetInstalledVersions()
{
var activeVersion = GetActiveVersion();
Expand Down
1 change: 1 addition & 0 deletions NodeSwap/NodeSwap.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<NeutralLanguage>en-US</NeutralLanguage>
<!-- No NuGet package -->
<IsPackable>false</IsPackable>
<PackageVersion>1.3.0</PackageVersion>
</PropertyGroup>

<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
Expand Down
2 changes: 1 addition & 1 deletion NodeSwap/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private static int Main(string[] args)
rootCommand.Add(uninstallCommand);

var useCommand = new Command("use") {new Argument("version")};
useCommand.Description = "Switch to a specific version. Must be specific like `14.16.1`.";
useCommand.Description = "Switch to a specific version. May be `latest` or specific like `14.16.1`.";
useCommand.Handler = Container.GetInstance<UseCommand>();
rootCommand.Add(useCommand);

Expand Down

0 comments on commit 830ef3b

Please sign in to comment.