Make use of the `required` keyword

pull/980/head
Oleksii Holub 2 years ago
parent a8f89ec292
commit f3830247fe

@ -16,7 +16,7 @@ public abstract class TokenCommandBase : ICommand
EnvironmentVariable = "DISCORD_TOKEN", EnvironmentVariable = "DISCORD_TOKEN",
Description = "Authentication 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.")] [Obsolete("This option doesn't do anything. Kept for backwards compatibility.")]
[CommandOption( [CommandOption(

@ -18,7 +18,7 @@ public class ExportChannelsCommand : ExportCommandBase
IsRequired = true, IsRequired = true,
Description = "Channel ID(s)." Description = "Channel ID(s)."
)] )]
public IReadOnlyList<Snowflake> ChannelIds { get; init; } = Array.Empty<Snowflake>(); public required IReadOnlyList<Snowflake> ChannelIds { get; init; }
public override async ValueTask ExecuteAsync(IConsole console) public override async ValueTask ExecuteAsync(IConsole console)
{ {

@ -18,7 +18,7 @@ public class ExportGuildCommand : ExportCommandBase
IsRequired = true, IsRequired = true,
Description = "Guild ID." Description = "Guild ID."
)] )]
public Snowflake GuildId { get; init; } public required Snowflake GuildId { get; init; }
public override async ValueTask ExecuteAsync(IConsole console) public override async ValueTask ExecuteAsync(IConsole console)
{ {

@ -19,7 +19,7 @@ public class GetChannelsCommand : TokenCommandBase
IsRequired = true, IsRequired = true,
Description = "Guild ID." Description = "Guild ID."
)] )]
public Snowflake GuildId { get; init; } public required Snowflake GuildId { get; init; }
public override async ValueTask ExecuteAsync(IConsole console) public override async ValueTask ExecuteAsync(IConsole console)
{ {

@ -13,13 +13,9 @@
@inherits RazorBlade.HtmlTemplate @inherits RazorBlade.HtmlTemplate
@functions { @functions {
// RazorBlade does not provide built-in support for cancellation public required ExportContext ExportContext { get; init; }
// https://github.com/ltrzesniewski/RazorBlade/issues/2
public CancellationToken CancellationToken { get; init; }
public ExportContext ExportContext { get; init; } = default!; public required IReadOnlyList<Message> Messages { get; init; }
public IReadOnlyList<Message> Messages { get; init; } = Array.Empty<Message>();
} }
@{ @{

@ -4,13 +4,9 @@
@inherits RazorBlade.HtmlTemplate @inherits RazorBlade.HtmlTemplate
@functions { @functions {
// RazorBlade does not provide built-in support for cancellation public required ExportContext ExportContext { get; init; }
// https://github.com/ltrzesniewski/RazorBlade/issues/2
public CancellationToken CancellationToken { get; init; }
public ExportContext ExportContext { get; init; } = default!; public required long MessagesWritten { get; init; }
public long MessagesWritten { get; init; }
} }
@{ @{

@ -7,13 +7,9 @@
@inherits RazorBlade.HtmlTemplate @inherits RazorBlade.HtmlTemplate
@functions { @functions {
// RazorBlade does not provide built-in support for cancellation public required ExportContext ExportContext { get; init; }
// https://github.com/ltrzesniewski/RazorBlade/issues/2
public CancellationToken CancellationToken { get; init; }
public ExportContext ExportContext { get; init; } = default!; public required string ThemeName { get; init; }
public string ThemeName { get; init; } = "Dark";
} }
@{ @{

@ -78,10 +78,9 @@ internal class HtmlMessageWriter : MessageWriter
Minify( Minify(
await new PreambleTemplate await new PreambleTemplate
{ {
CancellationToken = cancellationToken,
ExportContext = Context, ExportContext = Context,
ThemeName = _themeName ThemeName = _themeName
}.RenderAsync() }.RenderAsync(cancellationToken)
) )
); );
} }
@ -94,10 +93,9 @@ internal class HtmlMessageWriter : MessageWriter
Minify( Minify(
await new MessageGroupTemplate await new MessageGroupTemplate
{ {
CancellationToken = cancellationToken,
ExportContext = Context, ExportContext = Context,
Messages = messages Messages = messages
}.RenderAsync() }.RenderAsync(cancellationToken)
) )
); );
} }
@ -133,10 +131,9 @@ internal class HtmlMessageWriter : MessageWriter
Minify( Minify(
await new PostambleTemplate await new PostambleTemplate
{ {
CancellationToken = cancellationToken,
ExportContext = Context, ExportContext = Context,
MessagesWritten = MessagesWritten MessagesWritten = MessagesWritten
}.RenderAsync() }.RenderAsync(cancellationToken)
) )
); );
} }

Loading…
Cancel
Save