Skip to content
This repository has been archived by the owner on Dec 25, 2024. It is now read-only.

Allow skipping of update checks using config of --skip-update-checks #162

Merged
merged 1 commit into from
Jul 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/FaluCli/Commands/Config/ConfigCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public async Task<int> InvokeAsync(InvocationContext context)

var data = new Dictionary<string, object?>
{
["skip-update-check"] = values.SkipUpdateChecks,
["retries"] = values.Retries,
["timeout"] = $"{values.Timeout} seconds",
["workspace"] = values.DefaultWorkspaceId,
Expand Down Expand Up @@ -56,6 +57,9 @@ public async Task<int> InvokeAsync(InvocationContext context)
var value = context.ParseResult.ValueForArgument<string>("value")!;
switch (key)
{
case "skip-update-check":
values.SkipUpdateChecks = bool.Parse(value);
break;
case "retries":
values.Retries = int.Parse(value);
break;
Expand Down
4 changes: 4 additions & 0 deletions src/FaluCli/Config/ConfigValues.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
using System.Diagnostics.CodeAnalysis;
using System.Text.Json.Serialization;

namespace Falu.Config;

internal record ConfigValues
{
[JsonPropertyName("skip-update-checks")]
public bool SkipUpdateChecks { get; set; }

public int Retries { get; set; } = 0;
public int Timeout { get; set; } = 120;
public string? DefaultWorkspaceId { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions src/FaluCli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using Falu.Websockets;
using System.CommandLine.Builder;
using System.CommandLine.Hosting;
using Res = Falu.Properties.Resources;

// Create a root command with some options
var rootCommand = new RootCommand
Expand Down Expand Up @@ -72,6 +73,7 @@

rootCommand.Description = "Official CLI tool for Falu.";
rootCommand.AddGlobalOption(new[] { "-v", "--verbose" }, "Whether to output verbosely.", false);
rootCommand.AddGlobalOption<bool?>(new[] { "--skip-update-checks", }, Res.SkipUpdateCheckOptionDescription); // nullable so as to allow checking if specified

var builder = new CommandLineBuilder(rootCommand)
.UseHost(_ => Host.CreateDefaultBuilder(args), host =>
Expand Down
11 changes: 11 additions & 0 deletions src/FaluCli/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/FaluCli/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ falu config clear auth</value>
<data name="RequestIdFormat" xml:space="preserve">
<value>Request Id: {0}</value>
</data>
<data name="SkipUpdateCheckOptionDescription" xml:space="preserve">
<value>Whether to skip update checks.
This value can also be set globally using 'falu config set skip-update-check true'
This option overrides any value set in the configuration.</value>
</data>
<data name="TooManyMessagesToBeSent" xml:space="preserve">
<value>Message destinations (to) cannot exceed {0:n0} in one request.</value>
</data>
Expand Down
15 changes: 12 additions & 3 deletions src/FaluCli/Updates/UpdateChecker.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Net.Http.Json;
using Falu.Config;
using System.Net.Http.Json;

namespace Falu.Updates;

Expand All @@ -11,11 +12,15 @@ internal class UpdateChecker : BackgroundService
private static string? latestVersionBody;

private readonly IHostEnvironment environment;
private readonly IConfigValuesProvider configValuesProvider;
private readonly InvocationContext invocationContext;
private readonly HttpClient httpClient;

public UpdateChecker(IHostEnvironment environment, HttpClient httpClient)
public UpdateChecker(IHostEnvironment environment, IConfigValuesProvider configValuesProvider, InvocationContext invocationContext, HttpClient httpClient)
{
this.environment = environment ?? throw new ArgumentNullException(nameof(environment));
this.configValuesProvider = configValuesProvider ?? throw new ArgumentNullException(nameof(configValuesProvider));
this.invocationContext = invocationContext ?? throw new ArgumentNullException(nameof(invocationContext));
this.httpClient = httpClient ?? throw new ArgumentNullException(nameof(httpClient));
}

Expand All @@ -25,7 +30,11 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
{
if (environment.IsDevelopment() || latestVersion is not null) return;

// TODO: skip if configValues or command option says no update checks
// skip update checks if the configuration values say so or the command has overriden the value.
var skipUpdateChecks = (await configValuesProvider.GetConfigValuesAsync(stoppingToken)).SkipUpdateChecks;
var skipUpdateChecksOption = invocationContext.ParseResult.ValueForOption<bool?>("--skip-update-checks");
if (skipUpdateChecksOption is not null) skipUpdateChecks = skipUpdateChecksOption.Value;
if (skipUpdateChecks) return;

try
{
Expand Down