From f3830247fe6ae6f50bb5f333dde7f58518f75929 Mon Sep 17 00:00:00 2001 From: Oleksii Holub <1935960+Tyrrrz@users.noreply.github.com> Date: Thu, 8 Dec 2022 03:20:28 +0200 Subject: [PATCH] Make use of the `required` keyword --- .../Commands/Base/TokenCommandBase.cs | 2 +- .../Commands/ExportChannelsCommand.cs | 2 +- DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs | 2 +- DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs | 2 +- .../Exporting/Writers/Html/MessageGroupTemplate.cshtml | 8 ++------ .../Exporting/Writers/Html/PostambleTemplate.cshtml | 8 ++------ .../Exporting/Writers/Html/PreambleTemplate.cshtml | 8 ++------ .../Exporting/Writers/HtmlMessageWriter.cs | 9 +++------ 8 files changed, 13 insertions(+), 28 deletions(-) diff --git a/DiscordChatExporter.Cli/Commands/Base/TokenCommandBase.cs b/DiscordChatExporter.Cli/Commands/Base/TokenCommandBase.cs index 5a2deb7..d183f94 100644 --- a/DiscordChatExporter.Cli/Commands/Base/TokenCommandBase.cs +++ b/DiscordChatExporter.Cli/Commands/Base/TokenCommandBase.cs @@ -16,7 +16,7 @@ public abstract class TokenCommandBase : ICommand EnvironmentVariable = "DISCORD_TOKEN", Description = "Authentication token." )] - public string Token { get; init; } = ""; + public required string Token { get; init; } [Obsolete("This option doesn't do anything. Kept for backwards compatibility.")] [CommandOption( diff --git a/DiscordChatExporter.Cli/Commands/ExportChannelsCommand.cs b/DiscordChatExporter.Cli/Commands/ExportChannelsCommand.cs index e61b265..bc398af 100644 --- a/DiscordChatExporter.Cli/Commands/ExportChannelsCommand.cs +++ b/DiscordChatExporter.Cli/Commands/ExportChannelsCommand.cs @@ -18,7 +18,7 @@ public class ExportChannelsCommand : ExportCommandBase IsRequired = true, Description = "Channel ID(s)." )] - public IReadOnlyList ChannelIds { get; init; } = Array.Empty(); + public required IReadOnlyList ChannelIds { get; init; } public override async ValueTask ExecuteAsync(IConsole console) { diff --git a/DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs b/DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs index 77f4377..75c8903 100644 --- a/DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs +++ b/DiscordChatExporter.Cli/Commands/ExportGuildCommand.cs @@ -18,7 +18,7 @@ public class ExportGuildCommand : ExportCommandBase IsRequired = true, Description = "Guild ID." )] - public Snowflake GuildId { get; init; } + public required Snowflake GuildId { get; init; } public override async ValueTask ExecuteAsync(IConsole console) { diff --git a/DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs b/DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs index 187ef4b..018f546 100644 --- a/DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs +++ b/DiscordChatExporter.Cli/Commands/GetChannelsCommand.cs @@ -19,7 +19,7 @@ public class GetChannelsCommand : TokenCommandBase IsRequired = true, Description = "Guild ID." )] - public Snowflake GuildId { get; init; } + public required Snowflake GuildId { get; init; } public override async ValueTask ExecuteAsync(IConsole console) { diff --git a/DiscordChatExporter.Core/Exporting/Writers/Html/MessageGroupTemplate.cshtml b/DiscordChatExporter.Core/Exporting/Writers/Html/MessageGroupTemplate.cshtml index e453a7b..051cc66 100644 --- a/DiscordChatExporter.Core/Exporting/Writers/Html/MessageGroupTemplate.cshtml +++ b/DiscordChatExporter.Core/Exporting/Writers/Html/MessageGroupTemplate.cshtml @@ -13,13 +13,9 @@ @inherits RazorBlade.HtmlTemplate @functions { - // RazorBlade does not provide built-in support for cancellation - // https://github.com/ltrzesniewski/RazorBlade/issues/2 - public CancellationToken CancellationToken { get; init; } + public required ExportContext ExportContext { get; init; } - public ExportContext ExportContext { get; init; } = default!; - - public IReadOnlyList Messages { get; init; } = Array.Empty(); + public required IReadOnlyList Messages { get; init; } } @{ diff --git a/DiscordChatExporter.Core/Exporting/Writers/Html/PostambleTemplate.cshtml b/DiscordChatExporter.Core/Exporting/Writers/Html/PostambleTemplate.cshtml index 0da2161..68ddcf8 100644 --- a/DiscordChatExporter.Core/Exporting/Writers/Html/PostambleTemplate.cshtml +++ b/DiscordChatExporter.Core/Exporting/Writers/Html/PostambleTemplate.cshtml @@ -4,13 +4,9 @@ @inherits RazorBlade.HtmlTemplate @functions { - // RazorBlade does not provide built-in support for cancellation - // https://github.com/ltrzesniewski/RazorBlade/issues/2 - public CancellationToken CancellationToken { get; init; } + public required ExportContext ExportContext { get; init; } - public ExportContext ExportContext { get; init; } = default!; - - public long MessagesWritten { get; init; } + public required long MessagesWritten { get; init; } } @{ diff --git a/DiscordChatExporter.Core/Exporting/Writers/Html/PreambleTemplate.cshtml b/DiscordChatExporter.Core/Exporting/Writers/Html/PreambleTemplate.cshtml index ec61d2e..7108858 100644 --- a/DiscordChatExporter.Core/Exporting/Writers/Html/PreambleTemplate.cshtml +++ b/DiscordChatExporter.Core/Exporting/Writers/Html/PreambleTemplate.cshtml @@ -7,13 +7,9 @@ @inherits RazorBlade.HtmlTemplate @functions { - // RazorBlade does not provide built-in support for cancellation - // https://github.com/ltrzesniewski/RazorBlade/issues/2 - public CancellationToken CancellationToken { get; init; } + public required ExportContext ExportContext { get; init; } - public ExportContext ExportContext { get; init; } = default!; - - public string ThemeName { get; init; } = "Dark"; + public required string ThemeName { get; init; } } @{ diff --git a/DiscordChatExporter.Core/Exporting/Writers/HtmlMessageWriter.cs b/DiscordChatExporter.Core/Exporting/Writers/HtmlMessageWriter.cs index 571f859..97dc71d 100644 --- a/DiscordChatExporter.Core/Exporting/Writers/HtmlMessageWriter.cs +++ b/DiscordChatExporter.Core/Exporting/Writers/HtmlMessageWriter.cs @@ -78,10 +78,9 @@ internal class HtmlMessageWriter : MessageWriter Minify( await new PreambleTemplate { - CancellationToken = cancellationToken, ExportContext = Context, ThemeName = _themeName - }.RenderAsync() + }.RenderAsync(cancellationToken) ) ); } @@ -94,10 +93,9 @@ internal class HtmlMessageWriter : MessageWriter Minify( await new MessageGroupTemplate { - CancellationToken = cancellationToken, ExportContext = Context, Messages = messages - }.RenderAsync() + }.RenderAsync(cancellationToken) ) ); } @@ -133,10 +131,9 @@ internal class HtmlMessageWriter : MessageWriter Minify( await new PostambleTemplate { - CancellationToken = cancellationToken, ExportContext = Context, MessagesWritten = MessagesWritten - }.RenderAsync() + }.RenderAsync(cancellationToken) ) ); }