diff --git a/src/cli/Sightengine.CLI/CliRuntime.cs b/src/cli/Sightengine.CLI/CliRuntime.cs index 40d00e0..3933f1e 100644 --- a/src/cli/Sightengine.CLI/CliRuntime.cs +++ b/src/cli/Sightengine.CLI/CliRuntime.cs @@ -17,7 +17,7 @@ internal static class CliRuntime private static readonly string[] ApiKeyEnvironmentVariables = [@"SIGHTENGINE_API_KEY"]; private const string CredentialFileDirectoryName = ".sightengine"; - public static async Task CreateClientAsync(ParseResult parseResult, CancellationToken cancellationToken = default) + public static async global::System.Threading.Tasks.Task CreateClientAsync(ParseResult parseResult, CancellationToken cancellationToken = default) { var apiKey = await TryResolveApiKeyAsync(parseResult, cancellationToken).ConfigureAwait(false); var authorizations = string.IsNullOrWhiteSpace(apiKey) @@ -46,7 +46,7 @@ internal static class CliRuntime "Design", "CA1031:Do not catch general exception types", Justification = "Generated CLI commands map unexpected failures to a stable exit code.")] - public static async Task RunAsync(Func action, CancellationToken cancellationToken = default) + public static async global::System.Threading.Tasks.Task RunAsync(Func action, CancellationToken cancellationToken = default) { try { @@ -75,13 +75,13 @@ public static async Task RunAsync(Func action, CancellationToken canc } } - public static async Task TryResolveApiKeyAsync(ParseResult parseResult, CancellationToken cancellationToken = default) + public static async global::System.Threading.Tasks.Task TryResolveApiKeyAsync(ParseResult parseResult, CancellationToken cancellationToken = default) { var probe = await ProbeAuthAsync(parseResult, cancellationToken).ConfigureAwait(false); return probe.Active?.RawValue; } - public static async Task GetAuthStatusAsync(ParseResult parseResult, CancellationToken cancellationToken = default) + public static async global::System.Threading.Tasks.Task GetAuthStatusAsync(ParseResult parseResult, CancellationToken cancellationToken = default) { var probe = await ProbeAuthAsync(parseResult, cancellationToken).ConfigureAwait(false); return new AuthStatusInfo( @@ -98,7 +98,7 @@ public static async Task GetAuthStatusAsync(ParseResult parseRes .ToArray()); } - public static async Task WriteUserSecretAsync(string name, string value, CancellationToken cancellationToken = default) + public static async global::System.Threading.Tasks.Task WriteUserSecretAsync(string name, string value, CancellationToken cancellationToken = default) { var path = GetUserSecretsPath(); var directory = Path.GetDirectoryName(path); @@ -113,7 +113,7 @@ public static async Task WriteUserSecretAsync(string name, string value, Cancell await File.WriteAllTextAsync(path, json, cancellationToken).ConfigureAwait(false); } - public static async Task ClearUserSecretAsync(string name, CancellationToken cancellationToken = default) + public static async global::System.Threading.Tasks.Task ClearUserSecretAsync(string name, CancellationToken cancellationToken = default) { var path = GetUserSecretsPath(); if (!File.Exists(path)) @@ -241,7 +241,7 @@ public static TimeSpan ParseDuration(string value, string optionName) - public static async Task ReadInputAsync( + public static async global::System.Threading.Tasks.Task ReadInputAsync( ParseResult parseResult, Option inputOption, Option requestJsonOption, @@ -284,7 +284,7 @@ public static TimeSpan ParseDuration(string value, string optionName) return await ReadFlexibleInputAsync(parseResult.GetValue(inputOption)!, cancellationToken).ConfigureAwait(false); } - public static async Task ReadRequestAsync( + public static async global::System.Threading.Tasks.Task ReadRequestAsync( ParseResult parseResult, Option inputOption, Option requestJsonOption, @@ -306,7 +306,7 @@ public static async Task ReadRequestAsync( : throw new CliException($"Unable to deserialize request JSON as {typeof(T).Name}."); } - public static async Task ReadRequestOrDefaultAsync( + public static async global::System.Threading.Tasks.Task ReadRequestOrDefaultAsync( ParseResult parseResult, Option inputOption, Option requestJsonOption, @@ -367,19 +367,19 @@ public static string SerializeStringArray(IEnumerable values) return JsonSerializer.Serialize(values.ToArray()); } - public static async Task WriteJsonAsync(ParseResult parseResult, T value, JsonSerializerContext context, CancellationToken cancellationToken = default) + public static async global::System.Threading.Tasks.Task WriteJsonAsync(ParseResult parseResult, T value, JsonSerializerContext context, CancellationToken cancellationToken = default) { var json = JsonSerializer.Serialize(value, typeof(T), context); await WriteTextAsync(parseResult, PrettyJson(json), cancellationToken: cancellationToken).ConfigureAwait(false); } - public static async Task WriteJsonLineAsync(ParseResult parseResult, T value, JsonSerializerContext context, CancellationToken cancellationToken = default) + public static async global::System.Threading.Tasks.Task WriteJsonLineAsync(ParseResult parseResult, T value, JsonSerializerContext context, CancellationToken cancellationToken = default) { var json = JsonSerializer.Serialize(value, typeof(T), context); await WriteTextAsync(parseResult, json + Environment.NewLine, append: true, cancellationToken: cancellationToken).ConfigureAwait(false); } - public static async Task WriteResponseAsync( + public static async global::System.Threading.Tasks.Task WriteResponseAsync( ParseResult parseResult, T value, JsonSerializerContext context, @@ -399,7 +399,7 @@ public static async Task WriteResponseAsync( await WriteTextAsync(parseResult, text, cancellationToken: cancellationToken).ConfigureAwait(false); } - public static async Task WriteResponseLineAsync( + public static async global::System.Threading.Tasks.Task WriteResponseLineAsync( ParseResult parseResult, T value, JsonSerializerContext context, @@ -419,7 +419,7 @@ public static async Task WriteResponseLineAsync( await WriteTextAsync(parseResult, text + Environment.NewLine, append: true, cancellationToken: cancellationToken).ConfigureAwait(false); } - public static async Task TryWriteOutputDirectoryAsync( + public static async global::System.Threading.Tasks.Task TryWriteOutputDirectoryAsync( ParseResult parseResult, T value, JsonSerializerContext context, @@ -445,7 +445,7 @@ public static async Task TryWriteOutputDirectoryAsync( return true; } - public static async Task WriteSuccessAsync(ParseResult parseResult, CancellationToken cancellationToken = default) + public static async global::System.Threading.Tasks.Task WriteSuccessAsync(ParseResult parseResult, CancellationToken cancellationToken = default) { if (parseResult.GetValue(CliOptions.Json)) { @@ -456,7 +456,7 @@ public static async Task WriteSuccessAsync(ParseResult parseResult, Cancellation await WriteTextAsync(parseResult, "success: true", cancellationToken: cancellationToken).ConfigureAwait(false); } - public static async Task WriteBinaryAsync(ParseResult parseResult, byte[] bytes, CancellationToken cancellationToken = default) + public static async global::System.Threading.Tasks.Task WriteBinaryAsync(ParseResult parseResult, byte[] bytes, CancellationToken cancellationToken = default) { var outputPath = parseResult.GetValue(CliOptions.Output); if (string.IsNullOrWhiteSpace(outputPath)) @@ -467,7 +467,7 @@ public static async Task WriteBinaryAsync(ParseResult parseResult, byte[] bytes, await WriteBytesAsync(outputPath, bytes, cancellationToken).ConfigureAwait(false); } - public static async Task WriteStreamAsync(ParseResult parseResult, Stream stream, CancellationToken cancellationToken = default) + public static async global::System.Threading.Tasks.Task WriteStreamAsync(ParseResult parseResult, Stream stream, CancellationToken cancellationToken = default) { var outputPath = parseResult.GetValue(CliOptions.Output); if (string.IsNullOrWhiteSpace(outputPath)) @@ -504,13 +504,13 @@ public static string MaskSecret(string secret) return string.IsNullOrWhiteSpace(baseUrl) ? null : new Uri(baseUrl, UriKind.Absolute); } - private static async Task ReadUserSecretAsync(string name, CancellationToken cancellationToken = default) + private static async global::System.Threading.Tasks.Task ReadUserSecretAsync(string name, CancellationToken cancellationToken = default) { var values = await ReadUserSecretsAsync(cancellationToken).ConfigureAwait(false); return values.TryGetValue(name, out var value) && !string.IsNullOrWhiteSpace(value) ? value : null; } - private static async Task ReadCredentialFileAsync(CancellationToken cancellationToken = default) + private static async global::System.Threading.Tasks.Task ReadCredentialFileAsync(CancellationToken cancellationToken = default) { var path = GetCredentialFilePath(); if (string.IsNullOrWhiteSpace(path) || !File.Exists(path)) @@ -522,7 +522,7 @@ public static string MaskSecret(string secret) return string.IsNullOrWhiteSpace(value) ? null : value.Trim(); } - private static async Task> ReadUserSecretsAsync(CancellationToken cancellationToken = default) + private static async global::System.Threading.Tasks.Task> ReadUserSecretsAsync(CancellationToken cancellationToken = default) { var path = GetUserSecretsPath(); if (!File.Exists(path)) @@ -540,7 +540,7 @@ private static async Task> ReadUserSecretsAsync(Cance new Dictionary(StringComparer.Ordinal); } - private static async Task WriteTextAsync(ParseResult parseResult, string text, bool append = false, CancellationToken cancellationToken = default) + private static async global::System.Threading.Tasks.Task WriteTextAsync(ParseResult parseResult, string text, bool append = false, CancellationToken cancellationToken = default) { var outputPath = parseResult.GetValue(CliOptions.Output); if (string.IsNullOrWhiteSpace(outputPath)) @@ -570,7 +570,7 @@ private static async Task WriteTextAsync(ParseResult parseResult, string text, b } } - private static async Task WriteBytesAsync(string outputPath, byte[] bytes, CancellationToken cancellationToken = default) + private static async global::System.Threading.Tasks.Task WriteBytesAsync(string outputPath, byte[] bytes, CancellationToken cancellationToken = default) { var directory = Path.GetDirectoryName(outputPath); if (!string.IsNullOrWhiteSpace(directory)) @@ -586,12 +586,12 @@ private static bool EndsWithUnit(string value, char unit) return value.Length > 1 && value[^1] == unit; } - private static async Task WriteDeprecatedOptionWarningAsync(string oldOption, string replacement) + private static async global::System.Threading.Tasks.Task WriteDeprecatedOptionWarningAsync(string oldOption, string replacement) { await Console.Error.WriteLineAsync($"Warning: {oldOption} is deprecated; use {replacement}.").ConfigureAwait(false); } - private static async Task ReadFlexibleInputAsync(string input, CancellationToken cancellationToken = default) + private static async global::System.Threading.Tasks.Task ReadFlexibleInputAsync(string input, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(input)) { @@ -612,7 +612,7 @@ private static async Task ReadFlexibleInputAsync(string input, Cancellat return await ReadFileOrStdinAsync(input, cancellationToken).ConfigureAwait(false); } - private static async Task ReadFileOrStdinAsync(string pathOrDash, CancellationToken cancellationToken = default) + private static async global::System.Threading.Tasks.Task ReadFileOrStdinAsync(string pathOrDash, CancellationToken cancellationToken = default) { if (pathOrDash == "-") { @@ -830,7 +830,7 @@ private static void AppendLine(StringBuilder builder, int indent, string value) builder.AppendLine(value); } - private static async Task WriteItemFilesAsync(string outputDirectory, JsonArray items, CancellationToken cancellationToken = default) + private static async global::System.Threading.Tasks.Task WriteItemFilesAsync(string outputDirectory, JsonArray items, CancellationToken cancellationToken = default) { Directory.CreateDirectory(outputDirectory); @@ -880,7 +880,7 @@ await File.WriteAllTextAsync( } } - private static async Task TryWriteTextPropertyAsync( + private static async global::System.Threading.Tasks.Task TryWriteTextPropertyAsync( JsonObject item, string outputDirectory, string baseName, @@ -946,7 +946,7 @@ private static string SanitizeFileName(string value) return normalized; } - private static async Task WriteApiExceptionAsync(global::Sightengine.ApiException exception) + private static async global::System.Threading.Tasks.Task WriteApiExceptionAsync(global::Sightengine.ApiException exception) { var builder = new StringBuilder(); builder.Append("API error "); @@ -974,7 +974,7 @@ private static string PrettyJson(string json) return Encoding.UTF8.GetString(stream.ToArray()); } - private static async Task ProbeAuthAsync(ParseResult parseResult, CancellationToken cancellationToken = default) + private static async global::System.Threading.Tasks.Task ProbeAuthAsync(ParseResult parseResult, CancellationToken cancellationToken = default) { var optionSource = new AuthSourceProbe( Source: "option", diff --git a/src/cli/Sightengine.CLI/Commands/CheckTextCommandApiCommand.g.cs b/src/cli/Sightengine.CLI/Commands/CheckTextCommandApiCommand.g.cs index 9a7e2ea..daf95cd 100644 --- a/src/cli/Sightengine.CLI/Commands/CheckTextCommandApiCommand.g.cs +++ b/src/cli/Sightengine.CLI/Commands/CheckTextCommandApiCommand.g.cs @@ -110,7 +110,7 @@ await CliRuntime.RunAsync(async () => var text = parseResult.GetRequiredValue(Text); var lang = parseResult.GetRequiredValue(Lang); var mode = parseResult.GetRequiredValue(Mode); - var optCountries = CliRuntime.WasSpecified(parseResult, OptCountries) ? parseResult.GetValue(OptCountries) : __requestBase is not null ? __requestBase.OptCountries : default; + var optCountries = CliRuntime.WasSpecified(parseResult, OptCountries) ? parseResult.GetValue(OptCountries) : (__requestBase is { } __OptCountriesBaseValue ? __OptCountriesBaseValue.OptCountries : default); using var client = await CliRuntime.CreateClientAsync(parseResult, cancellationToken).ConfigureAwait(false); diff --git a/src/cli/Sightengine.CLI/Commands/CheckVideoAsyncCommandApiCommand.g.cs b/src/cli/Sightengine.CLI/Commands/CheckVideoAsyncCommandApiCommand.g.cs index 57e517b..2cd7f60 100644 --- a/src/cli/Sightengine.CLI/Commands/CheckVideoAsyncCommandApiCommand.g.cs +++ b/src/cli/Sightengine.CLI/Commands/CheckVideoAsyncCommandApiCommand.g.cs @@ -115,10 +115,10 @@ await CliRuntime.RunAsync(async () => RequestFile, global::Sightengine.SourceGenerationContext.Default, cancellationToken).ConfigureAwait(false); - var media = CliRuntime.WasSpecified(parseResult, Media) ? parseResult.GetValue(Media) : __requestBase is not null ? __requestBase.Media : default; - var medianame = CliRuntime.WasSpecified(parseResult, Medianame) ? parseResult.GetValue(Medianame) : __requestBase is not null ? __requestBase.Medianame : default; - var streamUrl = CliRuntime.WasSpecified(parseResult, StreamUrl) ? parseResult.GetValue(StreamUrl) : __requestBase is not null ? __requestBase.StreamUrl : default; - var callbackUrl = CliRuntime.WasSpecified(parseResult, CallbackUrl) ? parseResult.GetValue(CallbackUrl) : __requestBase is not null ? __requestBase.CallbackUrl : default; + var media = CliRuntime.WasSpecified(parseResult, Media) ? parseResult.GetValue(Media) : (__requestBase is { } __MediaBaseValue ? __MediaBaseValue.Media : default); + var medianame = CliRuntime.WasSpecified(parseResult, Medianame) ? parseResult.GetValue(Medianame) : (__requestBase is { } __MedianameBaseValue ? __MedianameBaseValue.Medianame : default); + var streamUrl = CliRuntime.WasSpecified(parseResult, StreamUrl) ? parseResult.GetValue(StreamUrl) : (__requestBase is { } __StreamUrlBaseValue ? __StreamUrlBaseValue.StreamUrl : default); + var callbackUrl = CliRuntime.WasSpecified(parseResult, CallbackUrl) ? parseResult.GetValue(CallbackUrl) : (__requestBase is { } __CallbackUrlBaseValue ? __CallbackUrlBaseValue.CallbackUrl : default); var models = parseResult.GetRequiredValue(Models); using var client = await CliRuntime.CreateClientAsync(parseResult, cancellationToken).ConfigureAwait(false); diff --git a/src/cli/Sightengine.CLI/Commands/CheckVideoSyncCommandApiCommand.g.cs b/src/cli/Sightengine.CLI/Commands/CheckVideoSyncCommandApiCommand.g.cs index 482319c..bde3cb6 100644 --- a/src/cli/Sightengine.CLI/Commands/CheckVideoSyncCommandApiCommand.g.cs +++ b/src/cli/Sightengine.CLI/Commands/CheckVideoSyncCommandApiCommand.g.cs @@ -106,9 +106,9 @@ await CliRuntime.RunAsync(async () => RequestFile, global::Sightengine.SourceGenerationContext.Default, cancellationToken).ConfigureAwait(false); - var media = CliRuntime.WasSpecified(parseResult, Media) ? parseResult.GetValue(Media) : __requestBase is not null ? __requestBase.Media : default; - var medianame = CliRuntime.WasSpecified(parseResult, Medianame) ? parseResult.GetValue(Medianame) : __requestBase is not null ? __requestBase.Medianame : default; - var streamUrl = CliRuntime.WasSpecified(parseResult, StreamUrl) ? parseResult.GetValue(StreamUrl) : __requestBase is not null ? __requestBase.StreamUrl : default; + var media = CliRuntime.WasSpecified(parseResult, Media) ? parseResult.GetValue(Media) : (__requestBase is { } __MediaBaseValue ? __MediaBaseValue.Media : default); + var medianame = CliRuntime.WasSpecified(parseResult, Medianame) ? parseResult.GetValue(Medianame) : (__requestBase is { } __MedianameBaseValue ? __MedianameBaseValue.Medianame : default); + var streamUrl = CliRuntime.WasSpecified(parseResult, StreamUrl) ? parseResult.GetValue(StreamUrl) : (__requestBase is { } __StreamUrlBaseValue ? __StreamUrlBaseValue.StreamUrl : default); var models = parseResult.GetRequiredValue(Models); using var client = await CliRuntime.CreateClientAsync(parseResult, cancellationToken).ConfigureAwait(false); diff --git a/src/cli/Sightengine.CLI/Commands/SubmitFeedbackCommandApiCommand.g.cs b/src/cli/Sightengine.CLI/Commands/SubmitFeedbackCommandApiCommand.g.cs index a57d759..5b5c511 100644 --- a/src/cli/Sightengine.CLI/Commands/SubmitFeedbackCommandApiCommand.g.cs +++ b/src/cli/Sightengine.CLI/Commands/SubmitFeedbackCommandApiCommand.g.cs @@ -115,9 +115,9 @@ await CliRuntime.RunAsync(async () => RequestFile, global::Sightengine.SourceGenerationContext.Default, cancellationToken).ConfigureAwait(false); - var url = CliRuntime.WasSpecified(parseResult, Url) ? parseResult.GetValue(Url) : __requestBase is not null ? __requestBase.Url : default; - var media = CliRuntime.WasSpecified(parseResult, Media) ? parseResult.GetValue(Media) : __requestBase is not null ? __requestBase.Media : default; - var medianame = CliRuntime.WasSpecified(parseResult, Medianame) ? parseResult.GetValue(Medianame) : __requestBase is not null ? __requestBase.Medianame : default; + var url = CliRuntime.WasSpecified(parseResult, Url) ? parseResult.GetValue(Url) : (__requestBase is { } __UrlBaseValue ? __UrlBaseValue.Url : default); + var media = CliRuntime.WasSpecified(parseResult, Media) ? parseResult.GetValue(Media) : (__requestBase is { } __MediaBaseValue ? __MediaBaseValue.Media : default); + var medianame = CliRuntime.WasSpecified(parseResult, Medianame) ? parseResult.GetValue(Medianame) : (__requestBase is { } __MedianameBaseValue ? __MedianameBaseValue.Medianame : default); var model = parseResult.GetRequiredValue(Model); var @class = parseResult.GetRequiredValue(Class); using var client = await CliRuntime.CreateClientAsync(parseResult, cancellationToken).ConfigureAwait(false);