mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Allow for skipping update check
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using System.ComponentModel;
|
||||
using System.ComponentModel;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Hosting;
|
||||
@@ -38,6 +38,11 @@ public class Program
|
||||
.SetRecursive(true)
|
||||
.SetDescription("'yes' by instead of 'no' in non-interactive prompts.");
|
||||
|
||||
public static CliOption<bool> SkipUpdatesOption { get; }
|
||||
= new CliOption<bool>("--skip-updates")
|
||||
.SetRecursive(true)
|
||||
.SetDescription("Skip update checks");
|
||||
|
||||
public static CliDirective WindowsDirective { get; } = new CliDirective("win") {
|
||||
Description = "Show and run Windows specific commands."
|
||||
};
|
||||
@@ -61,6 +66,7 @@ public class Program
|
||||
rootCommand.Options.Add(LegacyConsoleOption);
|
||||
rootCommand.Options.Add(YesOption);
|
||||
rootCommand.Options.Add(VerboseOption);
|
||||
rootCommand.Options.Add(SkipUpdatesOption);
|
||||
rootCommand.Directives.Add(WindowsDirective);
|
||||
rootCommand.Directives.Add(LinuxDirective);
|
||||
rootCommand.Directives.Add(OsxDirective);
|
||||
@@ -75,6 +81,7 @@ public class Program
|
||||
bool directiveWin = parseResult.GetResult(WindowsDirective) != null;
|
||||
bool directiveLinux = parseResult.GetResult(LinuxDirective) != null;
|
||||
bool directiveOsx = parseResult.GetResult(OsxDirective) != null;
|
||||
bool skipUpdates = parseResult.GetValue(SkipUpdatesOption);
|
||||
rootCommand.TreatUnmatchedTokensAsErrors = true;
|
||||
|
||||
var builder = Host.CreateEmptyApplicationBuilder(new HostApplicationBuilderSettings {
|
||||
@@ -102,7 +109,7 @@ public class Program
|
||||
targetOs = RuntimeOs.OSX;
|
||||
}
|
||||
|
||||
builder.Services.AddSingleton(new VelopackDefaults(defaultYes, targetOs));
|
||||
builder.Services.AddSingleton(new VelopackDefaults(defaultYes, targetOs, skipUpdates));
|
||||
|
||||
var host = builder.Build();
|
||||
var provider = host.Services;
|
||||
@@ -167,7 +174,7 @@ public class Program
|
||||
static void HideCommand(CliCommand command) => command.Hidden = true;
|
||||
}
|
||||
|
||||
private static void SetupConfig(IHostApplicationBuilder builder)
|
||||
private static void SetupConfig(HostApplicationBuilder builder)
|
||||
{
|
||||
//builder.Configuration.AddJsonFile("vpk.json", optional: true);
|
||||
builder.Configuration.AddEnvironmentVariables("VPK_");
|
||||
@@ -176,7 +183,7 @@ public class Program
|
||||
builder.Services.AddTransient(s => s.GetService<ILoggerFactory>().CreateLogger("vpk"));
|
||||
}
|
||||
|
||||
private static void SetupLogging(IHostApplicationBuilder builder, bool verbose, bool legacyConsole)
|
||||
private static void SetupLogging(HostApplicationBuilder builder, bool verbose, bool legacyConsole)
|
||||
{
|
||||
var levelSwitch = new LoggingLevelSwitch {
|
||||
MinimumLevel = verbose ? LogEventLevel.Debug : LogEventLevel.Information
|
||||
@@ -261,7 +268,7 @@ public static class ProgramCommandExtensions
|
||||
command.Initialize(logLevelSwitch);
|
||||
|
||||
logger.LogInformation($"[bold]{Program.INTRO}[/]");
|
||||
var updateCheck = new UpdateChecker(logger);
|
||||
var updateCheck = new UpdateChecker(logger, defaults);
|
||||
await updateCheck.CheckForUpdates();
|
||||
|
||||
command.SetProperties(ctx, config, defaults.TargetOs);
|
||||
|
||||
@@ -6,16 +6,20 @@ namespace Velopack.Vpk.Updates;
|
||||
public class UpdateChecker
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly VelopackDefaults _defaults;
|
||||
private IPackageSearchMetadata _cache;
|
||||
|
||||
public UpdateChecker(ILogger logger)
|
||||
public UpdateChecker(ILogger logger, VelopackDefaults defaults)
|
||||
{
|
||||
_logger = logger;
|
||||
_defaults = defaults;
|
||||
}
|
||||
|
||||
public async Task<bool> CheckForUpdates()
|
||||
{
|
||||
if (_defaults.SkipUpdates) return false;
|
||||
try {
|
||||
|
||||
var myVer = VelopackRuntimeInfo.VelopackNugetVersion;
|
||||
var isPre = myVer.IsPrerelease || myVer.HasMetadata;
|
||||
|
||||
|
||||
@@ -2,16 +2,18 @@
|
||||
|
||||
public record VelopackDefaults
|
||||
{
|
||||
public bool SkipUpdates { get; }
|
||||
public bool DefaultPromptValue { get; }
|
||||
public RuntimeOs TargetOs { get; }
|
||||
|
||||
public VelopackDefaults(bool defaultPromptValue)
|
||||
: this(defaultPromptValue, VelopackRuntimeInfo.SystemOs)
|
||||
: this(defaultPromptValue, VelopackRuntimeInfo.SystemOs, true)
|
||||
{
|
||||
}
|
||||
|
||||
public VelopackDefaults(bool defaultPromptValue, RuntimeOs targetOs)
|
||||
public VelopackDefaults(bool defaultPromptValue, RuntimeOs targetOs, bool skipUpdates)
|
||||
{
|
||||
SkipUpdates = skipUpdates;
|
||||
DefaultPromptValue = defaultPromptValue;
|
||||
TargetOs = targetOs;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user