Skip to content

Commit

Permalink
Add option to disable the update check (might not be desired in autom…
Browse files Browse the repository at this point in the history
…ation scenarios)
  • Loading branch information
christophwille committed Jul 13, 2023
1 parent 35a3d97 commit ca60ee8
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions ICSharpCode.ILSpyCmd/IlspyCmdProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

using Microsoft.Extensions.Hosting;

using NuGet.Versioning;

namespace ICSharpCode.ILSpyCmd
{
[Command(Name = "ilspycmd", Description = "dotnet tool for decompiling .NET assemblies and generating portable PDBs",
Expand Down Expand Up @@ -111,6 +113,9 @@ class ILSpyCmdProgram
[Option("--nested-directories", "Use nested directories for namespaces.", CommandOptionType.NoValue)]
public bool NestedDirectories { get; }

[Option("--disable-updatecheck", "If using ilspycmd in a tight loop or fully automated scenario, you might want to disable the automatic update check.", CommandOptionType.NoValue)]
public bool DisableUpdateCheck { get; }

private readonly IHostEnvironment _env;
public ILSpyCmdProgram(IHostEnvironment env)
{
Expand All @@ -119,7 +124,11 @@ public ILSpyCmdProgram(IHostEnvironment env)

private async Task<int> OnExecuteAsync(CommandLineApplication app)
{
var updateCheckTask = DotNetToolUpdateChecker.CheckForPackageUpdateAsync("ilspycmd");
Task<NuGetVersion> updateCheckTask = null;
if (!DisableUpdateCheck)
{
updateCheckTask = DotNetToolUpdateChecker.CheckForPackageUpdateAsync("ilspycmd");
}

TextWriter output = System.Console.Out;
string outputDirectory = ResolveOutputDirectory(OutputDirectory);
Expand Down Expand Up @@ -170,11 +179,14 @@ private async Task<int> OnExecuteAsync(CommandLineApplication app)
{
output.Close();

var latestVersion = await updateCheckTask;
if (null != latestVersion)
if (null != updateCheckTask)
{
Console.WriteLine("You are not using the latest version of the tool, please update.");
Console.WriteLine($"Latest version is '{latestVersion}'");
var latestVersion = await updateCheckTask;
if (null != latestVersion)
{
Console.WriteLine("You are not using the latest version of the tool, please update.");
Console.WriteLine($"Latest version is '{latestVersion}'");
}
}
}

Expand Down

0 comments on commit ca60ee8

Please sign in to comment.