diff --git a/src/Spectre.Console.Cli/ConfiguratorExtensions.cs b/src/Spectre.Console.Cli/ConfiguratorExtensions.cs
index 5ffaf96..630edb4 100644
--- a/src/Spectre.Console.Cli/ConfiguratorExtensions.cs
+++ b/src/Spectre.Console.Cli/ConfiguratorExtensions.cs
@@ -71,6 +71,23 @@ public static class ConfiguratorExtensions
configurator.Settings.StrictParsing = true;
return configurator;
+ }
+
+ ///
+ /// Tells the help writer whether or not to trim trailing period.
+ ///
+ /// The configurator.
+ /// True to trim trailing period (default), false to not.
+ /// A configurator that can be used to configure the application further.
+ public static IConfigurator TrimTrailingPeriods(this IConfigurator configurator, bool trimTrailingPeriods)
+ {
+ if (configurator == null)
+ {
+ throw new ArgumentNullException(nameof(configurator));
+ }
+
+ configurator.Settings.TrimTrailingPeriod = trimTrailingPeriods;
+ return configurator;
}
///
diff --git a/src/Spectre.Console.Cli/ICommandAppSettings.cs b/src/Spectre.Console.Cli/ICommandAppSettings.cs
index 8e89a78..6fb579b 100644
--- a/src/Spectre.Console.Cli/ICommandAppSettings.cs
+++ b/src/Spectre.Console.Cli/ICommandAppSettings.cs
@@ -34,7 +34,12 @@ public interface ICommandAppSettings
///
/// Gets or sets case sensitivity.
///
- CaseSensitivity CaseSensitivity { get; set; }
+ CaseSensitivity CaseSensitivity { get; set; }
+
+ ///
+ /// Gets or sets a value indicating whether trailing period of a description is trimmed.
+ ///
+ bool TrimTrailingPeriod { get; set; }
///
/// Gets or sets a value indicating whether or not parsing is strict.
diff --git a/src/Spectre.Console.Cli/Internal/Configuration/CommandAppSettings.cs b/src/Spectre.Console.Cli/Internal/Configuration/CommandAppSettings.cs
index 8fdfff3..4723bcb 100644
--- a/src/Spectre.Console.Cli/Internal/Configuration/CommandAppSettings.cs
+++ b/src/Spectre.Console.Cli/Internal/Configuration/CommandAppSettings.cs
@@ -10,13 +10,14 @@ internal sealed class CommandAppSettings : ICommandAppSettings
public CaseSensitivity CaseSensitivity { get; set; }
public bool PropagateExceptions { get; set; }
public bool ValidateExamples { get; set; }
+ public bool TrimTrailingPeriod { get; set; } = true;
public bool StrictParsing { get; set; }
public ParsingMode ParsingMode =>
StrictParsing ? ParsingMode.Strict : ParsingMode.Relaxed;
- public Func? ExceptionHandler { get; set; }
-
+ public Func? ExceptionHandler { get; set; }
+
public CommandAppSettings(ITypeRegistrar registrar)
{
Registrar = new TypeRegistrar(registrar);
diff --git a/src/Spectre.Console.Cli/Internal/HelpWriter.cs b/src/Spectre.Console.Cli/Internal/HelpWriter.cs
index 1f7cc37..8d6dcfa 100644
--- a/src/Spectre.Console.Cli/Internal/HelpWriter.cs
+++ b/src/Spectre.Console.Cli/Internal/HelpWriter.cs
@@ -373,11 +373,20 @@ internal static class HelpWriter
{
arguments.Style("silver", $"<{argument.Name.EscapeMarkup()}>");
arguments.Space();
- }
+ }
- grid.AddRow(
- arguments.ToString().TrimEnd(),
- child.Description ?? " ");
+ if (model.TrimTrailingPeriod)
+ {
+ grid.AddRow(
+ arguments.ToString().TrimEnd(),
+ child.Description?.TrimEnd('.') ?? " ");
+ }
+ else
+ {
+ grid.AddRow(
+ arguments.ToString().TrimEnd(),
+ child.Description ?? " ");
+ }
}
result.Add(grid);
diff --git a/src/Spectre.Console.Cli/Internal/Modelling/CommandModel.cs b/src/Spectre.Console.Cli/Internal/Modelling/CommandModel.cs
index e7a60c0..7068db4 100644
--- a/src/Spectre.Console.Cli/Internal/Modelling/CommandModel.cs
+++ b/src/Spectre.Console.Cli/Internal/Modelling/CommandModel.cs
@@ -6,7 +6,8 @@ internal sealed class CommandModel : ICommandContainer
public ParsingMode ParsingMode { get; }
public CommandInfo? DefaultCommand { get; }
public IList Commands { get; }
- public IList Examples { get; }
+ public IList Examples { get; }
+ public bool TrimTrailingPeriod { get; }
public CommandModel(
CommandAppSettings settings,
@@ -16,9 +17,10 @@ internal sealed class CommandModel : ICommandContainer
{
ApplicationName = settings.ApplicationName;
ParsingMode = settings.ParsingMode;
+ TrimTrailingPeriod = settings.TrimTrailingPeriod;
DefaultCommand = defaultCommand;
Commands = new List(commands ?? Array.Empty());
- Examples = new List(examples ?? Array.Empty());
+ Examples = new List(examples ?? Array.Empty());
}
public string GetApplicationName()
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 c016ef7..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,4 +1,4 @@
-DESCRIPTION:
+DESCRIPTION:
Contains settings for a cat.
USAGE:
@@ -14,4 +14,4 @@ OPTIONS:
--agility The agility between 0 and 100
COMMANDS:
- lion The lion command.
\ No newline at end of file
+ lion The lion command
\ No newline at end of file
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 8d9171d..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,4 +1,4 @@
-DESCRIPTION:
+DESCRIPTION:
The animal command.
USAGE:
@@ -15,5 +15,5 @@ OPTIONS:
-a, --alive Indicates whether or not the animal is alive
COMMANDS:
- dog The dog command.
- horse The horse command.
\ No newline at end of file
+ dog The dog command
+ horse The horse command
\ No newline at end of file
diff --git a/test/Spectre.Console.Cli.Tests/Expectations/Help/Description_No_Trailing_Period.Output.verified.txt b/test/Spectre.Console.Cli.Tests/Expectations/Help/Description_No_Trailing_Period.Output.verified.txt
new file mode 100644
index 0000000..b53e771
--- /dev/null
+++ b/test/Spectre.Console.Cli.Tests/Expectations/Help/Description_No_Trailing_Period.Output.verified.txt
@@ -0,0 +1,10 @@
+USAGE:
+ myapp [OPTIONS]
+
+OPTIONS:
+ -h, --help Prints help information
+ -v, --version Prints version information
+
+COMMANDS:
+ dog The dog command.
+ horse The horse command.
\ No newline at end of file
diff --git a/test/Spectre.Console.Cli.Tests/Expectations/Help/Hidden_Commands.Output.verified.txt b/test/Spectre.Console.Cli.Tests/Expectations/Help/Hidden_Commands.Output.verified.txt
index b53e771..6a792da 100644
--- a/test/Spectre.Console.Cli.Tests/Expectations/Help/Hidden_Commands.Output.verified.txt
+++ b/test/Spectre.Console.Cli.Tests/Expectations/Help/Hidden_Commands.Output.verified.txt
@@ -6,5 +6,5 @@ OPTIONS:
-v, --version Prints version information
COMMANDS:
- dog The dog command.
- horse The horse command.
\ No newline at end of file
+ dog The dog command
+ horse The horse command
\ No newline at end of file
diff --git a/test/Spectre.Console.Cli.Tests/Expectations/Help/Root.Output.verified.txt b/test/Spectre.Console.Cli.Tests/Expectations/Help/Root.Output.verified.txt
index cf1e2ac..366b6b3 100644
--- a/test/Spectre.Console.Cli.Tests/Expectations/Help/Root.Output.verified.txt
+++ b/test/Spectre.Console.Cli.Tests/Expectations/Help/Root.Output.verified.txt
@@ -6,6 +6,6 @@ OPTIONS:
-v, --version Prints version information
COMMANDS:
- dog The dog command.
- horse The horse command.
- giraffe The giraffe command.
\ No newline at end of file
+ dog The dog command
+ horse The horse command
+ giraffe The giraffe command
\ No newline at end of file
diff --git a/test/Spectre.Console.Cli.Tests/Expectations/Help/RootExamples.Output.verified.txt b/test/Spectre.Console.Cli.Tests/Expectations/Help/RootExamples.Output.verified.txt
index 248a766..6f5066a 100644
--- a/test/Spectre.Console.Cli.Tests/Expectations/Help/RootExamples.Output.verified.txt
+++ b/test/Spectre.Console.Cli.Tests/Expectations/Help/RootExamples.Output.verified.txt
@@ -10,5 +10,5 @@ OPTIONS:
-v, --version Prints version information
COMMANDS:
- dog The dog command.
- horse The horse command.
\ No newline at end of file
+ dog The dog command
+ horse The horse command
\ No newline at end of file
diff --git a/test/Spectre.Console.Cli.Tests/Expectations/Help/RootExamples_Children.Output.verified.txt b/test/Spectre.Console.Cli.Tests/Expectations/Help/RootExamples_Children.Output.verified.txt
index 248a766..6f5066a 100644
--- a/test/Spectre.Console.Cli.Tests/Expectations/Help/RootExamples_Children.Output.verified.txt
+++ b/test/Spectre.Console.Cli.Tests/Expectations/Help/RootExamples_Children.Output.verified.txt
@@ -10,5 +10,5 @@ OPTIONS:
-v, --version Prints version information
COMMANDS:
- dog The dog command.
- horse The horse command.
\ No newline at end of file
+ dog The dog command
+ horse The horse command
\ No newline at end of file
diff --git a/test/Spectre.Console.Cli.Tests/Expectations/Help/RootExamples_Leafs.Output.verified.txt b/test/Spectre.Console.Cli.Tests/Expectations/Help/RootExamples_Leafs.Output.verified.txt
index 3a8ccb5..7d3b86e 100644
--- a/test/Spectre.Console.Cli.Tests/Expectations/Help/RootExamples_Leafs.Output.verified.txt
+++ b/test/Spectre.Console.Cli.Tests/Expectations/Help/RootExamples_Leafs.Output.verified.txt
@@ -10,4 +10,4 @@ OPTIONS:
-v, --version Prints version information
COMMANDS:
- animal The animal command.
\ No newline at end of file
+ animal The animal command
\ No newline at end of file
diff --git a/test/Spectre.Console.Cli.Tests/Spectre.Console.Cli.Tests.csproj b/test/Spectre.Console.Cli.Tests/Spectre.Console.Cli.Tests.csproj
index 3b93029..06e7fc7 100644
--- a/test/Spectre.Console.Cli.Tests/Spectre.Console.Cli.Tests.csproj
+++ b/test/Spectre.Console.Cli.Tests/Spectre.Console.Cli.Tests.csproj
@@ -31,4 +31,15 @@
+
+
+ $([System.String]::Copy('%(FileName)').Split('.')[0])
+ %(ParentFile).cs
+
+
+ $([System.String]::Copy('%(FileName)').Split('.')[0])
+ %(ParentFile).cs
+
+
+
diff --git a/test/Spectre.Console.Cli.Tests/Unit/CommandAppTests.Help.cs b/test/Spectre.Console.Cli.Tests/Unit/CommandAppTests.Help.cs
index d2eeee0..87a9d3a 100644
--- a/test/Spectre.Console.Cli.Tests/Unit/CommandAppTests.Help.cs
+++ b/test/Spectre.Console.Cli.Tests/Unit/CommandAppTests.Help.cs
@@ -1,293 +1,319 @@
-namespace Spectre.Console.Tests.Unit.Cli;
-
-public sealed partial class CommandAppTests
-{
- [UsesVerify]
- [ExpectationPath("Help")]
- public class Help
- {
- [Fact]
- [Expectation("Root")]
- public Task Should_Output_Root_Correctly()
- {
- // Given
- var fixture = new CommandAppTester();
- fixture.Configure(configurator =>
- {
- configurator.SetApplicationName("myapp");
- configurator.AddCommand("dog");
- configurator.AddCommand("horse");
- configurator.AddCommand("giraffe");
- });
-
- // When
- var result = fixture.Run("--help");
-
- // Then
- return Verifier.Verify(result.Output);
- }
-
- [Fact]
- [Expectation("Hidden_Commands")]
- public Task Should_Skip_Hidden_Commands()
- {
- // Given
- var fixture = new CommandAppTester();
- fixture.Configure(configurator =>
- {
- configurator.SetApplicationName("myapp");
- configurator.AddCommand("dog");
- configurator.AddCommand("horse");
- configurator.AddCommand("giraffe")
- .WithExample(new[] { "giraffe", "123" })
- .IsHidden();
- });
-
- // When
- var result = fixture.Run("--help");
-
- // Then
- return Verifier.Verify(result.Output);
- }
-
- [Fact]
- [Expectation("Command")]
- public Task Should_Output_Command_Correctly()
- {
- // Given
- var fixture = new CommandAppTester();
- fixture.Configure(configurator =>
- {
- configurator.SetApplicationName("myapp");
- configurator.AddBranch("cat", animal =>
- {
- animal.SetDescription("Contains settings for a cat.");
- animal.AddCommand("lion");
- });
- });
-
- // When
- var result = fixture.Run("cat", "--help");
-
- // Then
- return Verifier.Verify(result.Output);
- }
-
- [Fact]
- [Expectation("Leaf")]
- public Task Should_Output_Leaf_Correctly()
- {
- // Given
- var fixture = new CommandAppTester();
- fixture.Configure(configurator =>
- {
- configurator.SetApplicationName("myapp");
- configurator.AddBranch("cat", animal =>
- {
- animal.SetDescription("Contains settings for a cat.");
- animal.AddCommand("lion");
- });
- });
-
- // When
- var result = fixture.Run("cat", "lion", "--help");
-
- // Then
- return Verifier.Verify(result.Output);
- }
-
- [Fact]
- [Expectation("Default")]
- public Task Should_Output_Default_Command_Correctly()
- {
- // Given
- var fixture = new CommandAppTester();
- fixture.SetDefaultCommand();
- fixture.Configure(configurator =>
- {
- configurator.SetApplicationName("myapp");
- });
-
- // When
- var result = fixture.Run("--help");
-
- // Then
- return Verifier.Verify(result.Output);
- }
-
- [Fact]
- [Expectation("RootExamples")]
- public Task Should_Output_Root_Examples_Defined_On_Root()
- {
- // Given
- var fixture = new CommandAppTester();
- fixture.Configure(configurator =>
- {
- configurator.SetApplicationName("myapp");
- configurator.AddExample(new[] { "dog", "--name", "Rufus", "--age", "12", "--good-boy" });
- configurator.AddExample(new[] { "horse", "--name", "Brutus" });
- configurator.AddCommand("dog");
- configurator.AddCommand("horse");
- });
-
- // When
- var result = fixture.Run("--help");
-
- // Then
- return Verifier.Verify(result.Output);
- }
-
- [Fact]
- [Expectation("RootExamples_Children")]
- public Task Should_Output_Root_Examples_Defined_On_Direct_Children_If_Root_Have_No_Examples()
- {
- // Given
- var fixture = new CommandAppTester();
- fixture.Configure(configurator =>
- {
- configurator.SetApplicationName("myapp");
- configurator.AddCommand("dog")
- .WithExample(new[] { "dog", "--name", "Rufus", "--age", "12", "--good-boy" });
- configurator.AddCommand("horse")
- .WithExample(new[] { "horse", "--name", "Brutus" });
- });
-
- // When
- var result = fixture.Run("--help");
-
- // Then
- return Verifier.Verify(result.Output);
- }
-
- [Fact]
- [Expectation("RootExamples_Leafs")]
- public Task Should_Output_Root_Examples_Defined_On_Leaves_If_No_Other_Examples_Are_Found()
- {
- // Given
- var fixture = new CommandAppTester();
- fixture.Configure(configurator =>
- {
- configurator.SetApplicationName("myapp");
- configurator.AddBranch("animal", animal =>
- {
- animal.SetDescription("The animal command.");
- animal.AddCommand("dog")
- .WithExample(new[] { "animal", "dog", "--name", "Rufus", "--age", "12", "--good-boy" });
- animal.AddCommand("horse")
- .WithExample(new[] { "animal", "horse", "--name", "Brutus" });
- });
- });
-
- // When
- var result = fixture.Run("--help");
-
- // Then
- return Verifier.Verify(result.Output);
- }
-
- [Fact]
- [Expectation("CommandExamples")]
- public Task Should_Only_Output_Command_Examples_Defined_On_Command()
- {
- // Given
- var fixture = new CommandAppTester();
- fixture.Configure(configurator =>
- {
- configurator.SetApplicationName("myapp");
- configurator.AddBranch("animal", animal =>
- {
- animal.SetDescription("The animal command.");
- animal.AddExample(new[] { "animal", "--help" });
-
- animal.AddCommand("dog")
- .WithExample(new[] { "animal", "dog", "--name", "Rufus", "--age", "12", "--good-boy" });
- animal.AddCommand("horse")
- .WithExample(new[] { "animal", "horse", "--name", "Brutus" });
- });
- });
-
- // When
- var result = fixture.Run("animal", "--help");
-
- // Then
- return Verifier.Verify(result.Output);
- }
-
- [Fact]
- [Expectation("DefaultExamples")]
- public Task Should_Output_Root_Examples_If_Default_Command_Is_Specified()
- {
- // Given
- var fixture = new CommandAppTester();
- fixture.SetDefaultCommand();
- fixture.Configure(configurator =>
- {
- configurator.SetApplicationName("myapp");
- configurator.AddExample(new[] { "12", "-c", "3" });
- });
-
- // When
- var result = fixture.Run("--help");
-
- // Then
- return Verifier.Verify(result.Output);
- }
-
- [Fact]
- [Expectation("NoDescription")]
- public Task Should_Not_Show_Truncated_Command_Table_If_Commands_Are_Missing_Description()
- {
- // Given
- var fixture = new CommandAppTester();
- fixture.Configure(configurator =>
- {
- configurator.SetApplicationName("myapp");
- configurator.AddCommand("bar");
- });
-
- // When
- var result = fixture.Run("--help");
-
- // Then
- return Verifier.Verify(result.Output);
- }
-
- [Fact]
- [Expectation("ArgumentOrder")]
- public Task Should_List_Arguments_In_Correct_Order()
- {
- // Given
- var fixture = new CommandAppTester();
- fixture.SetDefaultCommand>();
- fixture.Configure(configurator =>
- {
- configurator.SetApplicationName("myapp");
- });
-
- // When
- var result = fixture.Run("--help");
-
- // Then
- return Verifier.Verify(result.Output);
- }
-
- [Fact]
- [Expectation("Hidden_Command_Options")]
- public Task Should_Not_Show_Hidden_Command_Options()
- {
- // Given
- var fixture = new CommandAppTester();
- fixture.SetDefaultCommand>();
- fixture.Configure(configurator =>
- {
- configurator.SetApplicationName("myapp");
- });
-
- // When
- var result = fixture.Run("--help");
-
- // Then
- return Verifier.Verify(result.Output);
- }
- }
-}
+using Spectre.Console.Cli;
+
+namespace Spectre.Console.Tests.Unit.Cli;
+
+public sealed partial class CommandAppTests
+{
+ [UsesVerify]
+ [ExpectationPath("Help")]
+ public class Help
+ {
+ [Fact]
+ [Expectation("Root")]
+ public Task Should_Output_Root_Correctly()
+ {
+ // Given
+ var fixture = new CommandAppTester();
+ fixture.Configure(configurator =>
+ {
+ configurator.SetApplicationName("myapp");
+ configurator.AddCommand("dog");
+ configurator.AddCommand("horse");
+ configurator.AddCommand("giraffe");
+ });
+
+ // When
+ var result = fixture.Run("--help");
+
+ // Then
+ return Verifier.Verify(result.Output);
+ }
+
+ [Fact]
+ [Expectation("Hidden_Commands")]
+ public Task Should_Skip_Hidden_Commands()
+ {
+ // Given
+ var fixture = new CommandAppTester();
+ fixture.Configure(configurator =>
+ {
+ configurator.SetApplicationName("myapp");
+ configurator.AddCommand("dog");
+ configurator.AddCommand("horse");
+ configurator.AddCommand("giraffe")
+ .WithExample(new[] { "giraffe", "123" })
+ .IsHidden();
+ });
+
+ // When
+ var result = fixture.Run("--help");
+
+ // Then
+ return Verifier.Verify(result.Output);
+ }
+
+ [Fact]
+ [Expectation("Description_No_Trailing_Period")]
+ public Task Should_Not_Trim_Description_Trailing_Period()
+ {
+ // Given
+ var fixture = new CommandAppTester();
+ fixture.Configure(configurator =>
+ {
+ configurator.SetApplicationName("myapp");
+ configurator.AddCommand("dog");
+ configurator.AddCommand("horse");
+ configurator.AddCommand("giraffe")
+ .WithExample(new[] { "giraffe", "123" })
+ .IsHidden();
+ configurator.TrimTrailingPeriods(false);
+ });
+
+ // When
+ var result = fixture.Run("--help");
+
+ // Then
+ return Verifier.Verify(result.Output);
+ }
+
+ [Fact]
+ [Expectation("Command")]
+ public Task Should_Output_Command_Correctly()
+ {
+ // Given
+ var fixture = new CommandAppTester();
+ fixture.Configure(configurator =>
+ {
+ configurator.SetApplicationName("myapp");
+ configurator.AddBranch("cat", animal =>
+ {
+ animal.SetDescription("Contains settings for a cat.");
+ animal.AddCommand("lion");
+ });
+ });
+
+ // When
+ var result = fixture.Run("cat", "--help");
+
+ // Then
+ return Verifier.Verify(result.Output);
+ }
+
+ [Fact]
+ [Expectation("Leaf")]
+ public Task Should_Output_Leaf_Correctly()
+ {
+ // Given
+ var fixture = new CommandAppTester();
+ fixture.Configure(configurator =>
+ {
+ configurator.SetApplicationName("myapp");
+ configurator.AddBranch("cat", animal =>
+ {
+ animal.SetDescription("Contains settings for a cat.");
+ animal.AddCommand("lion");
+ });
+ });
+
+ // When
+ var result = fixture.Run("cat", "lion", "--help");
+
+ // Then
+ return Verifier.Verify(result.Output);
+ }
+
+ [Fact]
+ [Expectation("Default")]
+ public Task Should_Output_Default_Command_Correctly()
+ {
+ // Given
+ var fixture = new CommandAppTester();
+ fixture.SetDefaultCommand();
+ fixture.Configure(configurator =>
+ {
+ configurator.SetApplicationName("myapp");
+ });
+
+ // When
+ var result = fixture.Run("--help");
+
+ // Then
+ return Verifier.Verify(result.Output);
+ }
+
+ [Fact]
+ [Expectation("RootExamples")]
+ public Task Should_Output_Root_Examples_Defined_On_Root()
+ {
+ // Given
+ var fixture = new CommandAppTester();
+ fixture.Configure(configurator =>
+ {
+ configurator.SetApplicationName("myapp");
+ configurator.AddExample(new[] { "dog", "--name", "Rufus", "--age", "12", "--good-boy" });
+ configurator.AddExample(new[] { "horse", "--name", "Brutus" });
+ configurator.AddCommand("dog");
+ configurator.AddCommand("horse");
+ });
+
+ // When
+ var result = fixture.Run("--help");
+
+ // Then
+ return Verifier.Verify(result.Output);
+ }
+
+ [Fact]
+ [Expectation("RootExamples_Children")]
+ public Task Should_Output_Root_Examples_Defined_On_Direct_Children_If_Root_Have_No_Examples()
+ {
+ // Given
+ var fixture = new CommandAppTester();
+ fixture.Configure(configurator =>
+ {
+ configurator.SetApplicationName("myapp");
+ configurator.AddCommand("dog")
+ .WithExample(new[] { "dog", "--name", "Rufus", "--age", "12", "--good-boy" });
+ configurator.AddCommand("horse")
+ .WithExample(new[] { "horse", "--name", "Brutus" });
+ });
+
+ // When
+ var result = fixture.Run("--help");
+
+ // Then
+ return Verifier.Verify(result.Output);
+ }
+
+ [Fact]
+ [Expectation("RootExamples_Leafs")]
+ public Task Should_Output_Root_Examples_Defined_On_Leaves_If_No_Other_Examples_Are_Found()
+ {
+ // Given
+ var fixture = new CommandAppTester();
+ fixture.Configure(configurator =>
+ {
+ configurator.SetApplicationName("myapp");
+ configurator.AddBranch("animal", animal =>
+ {
+ animal.SetDescription("The animal command.");
+ animal.AddCommand("dog")
+ .WithExample(new[] { "animal", "dog", "--name", "Rufus", "--age", "12", "--good-boy" });
+ animal.AddCommand("horse")
+ .WithExample(new[] { "animal", "horse", "--name", "Brutus" });
+ });
+ });
+
+ // When
+ var result = fixture.Run("--help");
+
+ // Then
+ return Verifier.Verify(result.Output);
+ }
+
+ [Fact]
+ [Expectation("CommandExamples")]
+ public Task Should_Only_Output_Command_Examples_Defined_On_Command()
+ {
+ // Given
+ var fixture = new CommandAppTester();
+ fixture.Configure(configurator =>
+ {
+ configurator.SetApplicationName("myapp");
+ configurator.AddBranch("animal", animal =>
+ {
+ animal.SetDescription("The animal command.");
+ animal.AddExample(new[] { "animal", "--help" });
+
+ animal.AddCommand("dog")
+ .WithExample(new[] { "animal", "dog", "--name", "Rufus", "--age", "12", "--good-boy" });
+ animal.AddCommand("horse")
+ .WithExample(new[] { "animal", "horse", "--name", "Brutus" });
+ });
+ });
+
+ // When
+ var result = fixture.Run("animal", "--help");
+
+ // Then
+ return Verifier.Verify(result.Output);
+ }
+
+ [Fact]
+ [Expectation("DefaultExamples")]
+ public Task Should_Output_Root_Examples_If_Default_Command_Is_Specified()
+ {
+ // Given
+ var fixture = new CommandAppTester();
+ fixture.SetDefaultCommand();
+ fixture.Configure(configurator =>
+ {
+ configurator.SetApplicationName("myapp");
+ configurator.AddExample(new[] { "12", "-c", "3" });
+ });
+
+ // When
+ var result = fixture.Run("--help");
+
+ // Then
+ return Verifier.Verify(result.Output);
+ }
+
+ [Fact]
+ [Expectation("NoDescription")]
+ public Task Should_Not_Show_Truncated_Command_Table_If_Commands_Are_Missing_Description()
+ {
+ // Given
+ var fixture = new CommandAppTester();
+ fixture.Configure(configurator =>
+ {
+ configurator.SetApplicationName("myapp");
+ configurator.AddCommand("bar");
+ });
+
+ // When
+ var result = fixture.Run("--help");
+
+ // Then
+ return Verifier.Verify(result.Output);
+ }
+
+ [Fact]
+ [Expectation("ArgumentOrder")]
+ public Task Should_List_Arguments_In_Correct_Order()
+ {
+ // Given
+ var fixture = new CommandAppTester();
+ fixture.SetDefaultCommand>();
+ fixture.Configure(configurator =>
+ {
+ configurator.SetApplicationName("myapp");
+ });
+
+ // When
+ var result = fixture.Run("--help");
+
+ // Then
+ return Verifier.Verify(result.Output);
+ }
+
+ [Fact]
+ [Expectation("Hidden_Command_Options")]
+ public Task Should_Not_Show_Hidden_Command_Options()
+ {
+ // Given
+ var fixture = new CommandAppTester();
+ fixture.SetDefaultCommand>();
+ fixture.Configure(configurator =>
+ {
+ configurator.SetApplicationName("myapp");
+ });
+
+ // When
+ var result = fixture.Run("--help");
+
+ // Then
+ return Verifier.Verify(result.Output);
+ }
+ }
+}