From ddc1ae8537078c5d4259d9b5e201bc9aa66715aa Mon Sep 17 00:00:00 2001 From: Alexey Golub Date: Fri, 16 Aug 2019 17:43:50 +0300 Subject: [PATCH] Add application description to metadata --- CliFx.Tests.Dummy/Program.cs | 1 + CliFx/CliApplicationBuilder.cs | 10 +++++++++- CliFx/ICliApplicationBuilder.cs | 5 +++++ CliFx/Models/ApplicationMetadata.cs | 8 +++++++- CliFx/Services/CommandHelpTextRenderer.cs | 7 +++++++ 5 files changed, 29 insertions(+), 2 deletions(-) diff --git a/CliFx.Tests.Dummy/Program.cs b/CliFx.Tests.Dummy/Program.cs index 24b79cb..f40bd6d 100644 --- a/CliFx.Tests.Dummy/Program.cs +++ b/CliFx.Tests.Dummy/Program.cs @@ -7,6 +7,7 @@ namespace CliFx.Tests.Dummy public static Task Main(string[] args) => new CliApplicationBuilder() .WithCommandsFromThisAssembly() + .UseDescription("Dummy program used for E2E tests.") .Build() .RunAsync(args); } diff --git a/CliFx/CliApplicationBuilder.cs b/CliFx/CliApplicationBuilder.cs index e73874c..57c2ac7 100644 --- a/CliFx/CliApplicationBuilder.cs +++ b/CliFx/CliApplicationBuilder.cs @@ -19,6 +19,7 @@ namespace CliFx private string _title; private string _executableName; private string _versionText; + private string _description; private IConsole _console; private ICommandFactory _commandFactory; @@ -66,6 +67,13 @@ namespace CliFx return this; } + /// + public ICliApplicationBuilder UseDescription(string description) + { + _description = description; // can be null + return this; + } + /// public ICliApplicationBuilder UseConsole(IConsole console) { @@ -108,7 +116,7 @@ namespace CliFx SetFallbackValues(); // Project parameters to expected types - var metadata = new ApplicationMetadata(_title, _executableName, _versionText); + var metadata = new ApplicationMetadata(_title, _executableName, _versionText, _description); var commandTypes = _commandTypes.ToArray(); return new CliApplication(metadata, commandTypes, diff --git a/CliFx/ICliApplicationBuilder.cs b/CliFx/ICliApplicationBuilder.cs index 5bdbac5..93b05a3 100644 --- a/CliFx/ICliApplicationBuilder.cs +++ b/CliFx/ICliApplicationBuilder.cs @@ -34,6 +34,11 @@ namespace CliFx /// ICliApplicationBuilder UseVersionText(string versionText); + /// + /// Sets application description, which appears in the help text. + /// + ICliApplicationBuilder UseDescription(string description); + /// /// Configures application to use specified implementation of . /// diff --git a/CliFx/Models/ApplicationMetadata.cs b/CliFx/Models/ApplicationMetadata.cs index e7bd062..5003e95 100644 --- a/CliFx/Models/ApplicationMetadata.cs +++ b/CliFx/Models/ApplicationMetadata.cs @@ -22,14 +22,20 @@ namespace CliFx.Models /// public string VersionText { get; } + /// + /// Application description. + /// + public string Description { get; } + /// /// Initializes an instance of . /// - public ApplicationMetadata(string title, string executableName, string versionText) + public ApplicationMetadata(string title, string executableName, string versionText, string description) { Title = title.GuardNotNull(nameof(title)); ExecutableName = executableName.GuardNotNull(nameof(executableName)); VersionText = versionText.GuardNotNull(nameof(versionText)); + Description = description; // can be null } } } \ No newline at end of file diff --git a/CliFx/Services/CommandHelpTextRenderer.cs b/CliFx/Services/CommandHelpTextRenderer.cs index 143e97e..1888668 100644 --- a/CliFx/Services/CommandHelpTextRenderer.cs +++ b/CliFx/Services/CommandHelpTextRenderer.cs @@ -89,6 +89,13 @@ namespace CliFx.Services Render(" "); RenderWithColor(source.ApplicationMetadata.VersionText, ConsoleColor.Yellow); RenderNewLine(); + + // Description + if (!source.ApplicationMetadata.Description.IsNullOrWhiteSpace()) + { + Render(source.ApplicationMetadata.Description); + RenderNewLine(); + } } void RenderDescription()