From 15150cb3ed2a11ebee30644e55d8ff27a859be88 Mon Sep 17 00:00:00 2001 From: Oleksii Holub <1935960+Tyrrrz@users.noreply.github.com> Date: Thu, 8 Dec 2022 03:08:58 +0200 Subject: [PATCH] Add `required` modifiers --- CliFx.Demo/Commands/BookAddCommand.cs | 4 ++-- CliFx.Demo/Commands/BookCommand.cs | 2 +- CliFx.Demo/Commands/BookRemoveCommand.cs | 2 +- Readme.md | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/CliFx.Demo/Commands/BookAddCommand.cs b/CliFx.Demo/Commands/BookAddCommand.cs index a8f4e5d..725ef86 100644 --- a/CliFx.Demo/Commands/BookAddCommand.cs +++ b/CliFx.Demo/Commands/BookAddCommand.cs @@ -14,10 +14,10 @@ public partial class BookAddCommand : ICommand private readonly LibraryProvider _libraryProvider; [CommandParameter(0, Name = "title", Description = "Book title.")] - public string Title { get; init; } = ""; + public required string Title { get; init; } [CommandOption("author", 'a', IsRequired = true, Description = "Book author.")] - public string Author { get; init; } = ""; + public required string Author { get; init; } [CommandOption("published", 'p', Description = "Book publish date.")] public DateTimeOffset Published { get; init; } = CreateRandomDate(); diff --git a/CliFx.Demo/Commands/BookCommand.cs b/CliFx.Demo/Commands/BookCommand.cs index c5769aa..f181d4e 100644 --- a/CliFx.Demo/Commands/BookCommand.cs +++ b/CliFx.Demo/Commands/BookCommand.cs @@ -13,7 +13,7 @@ public class BookCommand : ICommand private readonly LibraryProvider _libraryProvider; [CommandParameter(0, Name = "title", Description = "Title of the book to retrieve.")] - public string Title { get; init; } = ""; + public required string Title { get; init; } public BookCommand(LibraryProvider libraryProvider) { diff --git a/CliFx.Demo/Commands/BookRemoveCommand.cs b/CliFx.Demo/Commands/BookRemoveCommand.cs index 04c1e1f..14290b0 100644 --- a/CliFx.Demo/Commands/BookRemoveCommand.cs +++ b/CliFx.Demo/Commands/BookRemoveCommand.cs @@ -12,7 +12,7 @@ public class BookRemoveCommand : ICommand private readonly LibraryProvider _libraryProvider; [CommandParameter(0, Name = "title", Description = "Title of the book to remove.")] - public string Title { get; init; } = ""; + public required string Title { get; init; } public BookRemoveCommand(LibraryProvider libraryProvider) { diff --git a/Readme.md b/Readme.md index d414b31..b34f1db 100644 --- a/Readme.md +++ b/Readme.md @@ -383,7 +383,7 @@ If the user does not provide value for such option through command line argument public class AuthCommand : ICommand { [CommandOption("token", IsRequired = true, EnvironmentVariable = "AUTH_TOKEN")] - public string AuthToken { get; init; } + public required string AuthToken { get; init; } public ValueTask ExecuteAsync(IConsole console) { @@ -500,10 +500,10 @@ This special exception can be used to print an error message to the console, ret public class DivideCommand : ICommand { [CommandOption("dividend", IsRequired = true)] - public double Dividend { get; init; } + public required double Dividend { get; init; } [CommandOption("divisor", IsRequired = true)] - public double Divisor { get; init; } + public required double Divisor { get; init; } public ValueTask ExecuteAsync(IConsole console) { @@ -727,4 +727,4 @@ var app = new CliApplicationBuilder() ## Etymology **CliFx** is made out of "Cli" for "Command Line Interface" and "Fx" for "Framework". -It's pronounced as "cliff ex". +It's pronounced as "cliff ex". \ No newline at end of file