From 78d841e3dcbfffcb2003f92bf32c436e6e714f7e Mon Sep 17 00:00:00 2001 From: nkochnev Date: Wed, 17 Aug 2022 19:59:08 +0500 Subject: [PATCH] Added command description to command help message (#920) --- src/Spectre.Console.Cli/Internal/HelpWriter.cs | 14 ++++++++++++++ .../Expectations/Help/Command.Output.verified.txt | 3 +++ .../Help/CommandExamples.Output.verified.txt | 3 +++ .../Expectations/Help/Default.Output.verified.txt | 3 +++ .../Help/DefaultExamples.Output.verified.txt | 3 +++ .../Expectations/Help/Leaf.Output.verified.txt | 3 +++ 6 files changed, 29 insertions(+) diff --git a/src/Spectre.Console.Cli/Internal/HelpWriter.cs b/src/Spectre.Console.Cli/Internal/HelpWriter.cs index e9f47f0..ee909e6 100644 --- a/src/Spectre.Console.Cli/Internal/HelpWriter.cs +++ b/src/Spectre.Console.Cli/Internal/HelpWriter.cs @@ -75,6 +75,7 @@ internal static class HelpWriter var isDefaultCommand = command?.IsDefaultCommand ?? false; var result = new List(); + result.AddRange(GetDescription(command)); result.AddRange(GetUsage(model, command)); result.AddRange(GetExamples(model, command)); result.AddRange(GetArguments(command)); @@ -84,6 +85,19 @@ internal static class HelpWriter return result; } + private static IEnumerable GetDescription(CommandInfo? command) + { + if (command?.Description == null) + { + yield break; + } + + var composer = new Composer(); + composer.Style("yellow", "DESCRIPTION:").LineBreak(); + composer.Text(command.Description).LineBreak(); + yield return composer.LineBreak(); + } + private static IEnumerable GetUsage(CommandModel model, CommandInfo? command) { var composer = new Composer(); diff --git a/test/Spectre.Console.Cli.Tests/Expectations/Help/Command.Output.verified.txt b/test/Spectre.Console.Cli.Tests/Expectations/Help/Command.Output.verified.txt index 1408721..0cf3f19 100644 --- a/test/Spectre.Console.Cli.Tests/Expectations/Help/Command.Output.verified.txt +++ b/test/Spectre.Console.Cli.Tests/Expectations/Help/Command.Output.verified.txt @@ -1,3 +1,6 @@ +DESCRIPTION: +Contains settings for a cat. + USAGE: myapp cat [LEGS] [OPTIONS] diff --git a/test/Spectre.Console.Cli.Tests/Expectations/Help/CommandExamples.Output.verified.txt b/test/Spectre.Console.Cli.Tests/Expectations/Help/CommandExamples.Output.verified.txt index ccadb2c..a45af87 100644 --- a/test/Spectre.Console.Cli.Tests/Expectations/Help/CommandExamples.Output.verified.txt +++ b/test/Spectre.Console.Cli.Tests/Expectations/Help/CommandExamples.Output.verified.txt @@ -1,3 +1,6 @@ +DESCRIPTION: +The animal command. + USAGE: myapp animal [LEGS] [OPTIONS] diff --git a/test/Spectre.Console.Cli.Tests/Expectations/Help/Default.Output.verified.txt b/test/Spectre.Console.Cli.Tests/Expectations/Help/Default.Output.verified.txt index f34969b..27df838 100644 --- a/test/Spectre.Console.Cli.Tests/Expectations/Help/Default.Output.verified.txt +++ b/test/Spectre.Console.Cli.Tests/Expectations/Help/Default.Output.verified.txt @@ -1,3 +1,6 @@ +DESCRIPTION: +The lion command. + USAGE: myapp [LEGS] [OPTIONS] diff --git a/test/Spectre.Console.Cli.Tests/Expectations/Help/DefaultExamples.Output.verified.txt b/test/Spectre.Console.Cli.Tests/Expectations/Help/DefaultExamples.Output.verified.txt index 725c159..81c1939 100644 --- a/test/Spectre.Console.Cli.Tests/Expectations/Help/DefaultExamples.Output.verified.txt +++ b/test/Spectre.Console.Cli.Tests/Expectations/Help/DefaultExamples.Output.verified.txt @@ -1,3 +1,6 @@ +DESCRIPTION: +The lion command. + USAGE: myapp [LEGS] [OPTIONS] diff --git a/test/Spectre.Console.Cli.Tests/Expectations/Help/Leaf.Output.verified.txt b/test/Spectre.Console.Cli.Tests/Expectations/Help/Leaf.Output.verified.txt index bceaf85..5754d72 100644 --- a/test/Spectre.Console.Cli.Tests/Expectations/Help/Leaf.Output.verified.txt +++ b/test/Spectre.Console.Cli.Tests/Expectations/Help/Leaf.Output.verified.txt @@ -1,3 +1,6 @@ +DESCRIPTION: +The lion command. + USAGE: myapp cat [LEGS] lion [OPTIONS]