Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,6 @@ public void Help_default_sections_can_be_wrapped()
command.Parse("test -h").Invoke(new() { Output = output });

output.ToString().Should().Be(
$"Description:{NewLine}{NewLine}" +
$"Usage:{NewLine} test [options]{NewLine}{NewLine}" +
$"Options:{NewLine}" +
$" --option option {NewLine}" +
Expand Down Expand Up @@ -534,4 +533,4 @@ private string GetDefaultHelp(Command command, bool trimOneNewline = true)
return output;
}
}
}
}
14 changes: 14 additions & 0 deletions src/System.CommandLine.Tests/Help/HelpBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ public void Synopsis_section_properly_wraps_description()
_console.ToString().Should().Contain(expected);
}

[Theory]
[InlineData("")]
[InlineData(" ")]
[InlineData(null)]
public void Synopsis_section_is_omitted_when_description_is_empty(string? description)
{
var command = new Command("the-command", description);

_helpBuilder.Write(command, _console);

_console.ToString().Should().NotContain("Description:");
_console.ToString().Should().Contain("Usage:");
}

[Fact]
public void Command_name_in_synopsis_can_be_specified()
{
Expand Down
10 changes: 5 additions & 5 deletions src/System.CommandLine.Tests/Utility/AssertionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public static AndConstraint<StringCollectionAssertions<IEnumerable<string>>> BeE
return assertions.BeEquivalentTo(expectedValues, c => c.WithStrictOrderingFor(s => s));
}

public static AndConstraint<StringAssertions> ShowHelp(this StringAssertions output) =>
output.Subject.Should().Match("*Description:*Usage:*");
public static AndConstraint<StringAssertions> ShowHelp(this StringAssertions output) =>
output.Subject.Should().Contain("Usage:");

public static AndConstraint<StringAssertions> NotShowHelp(this StringAssertions output) =>
output.Subject.Should().NotMatch("*Description:*Usage:*");
}
public static AndConstraint<StringAssertions> NotShowHelp(this StringAssertions output) =>
output.Subject.Should().NotContain("Usage:");
}
5 changes: 5 additions & 0 deletions src/System.CommandLine/Help/HelpBuilder.Default.cs
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,11 @@ public static IEnumerable<Func<HelpContext, bool>> GetLayout()
public static Func<HelpContext, bool> SynopsisSection() =>
ctx =>
{
if (string.IsNullOrWhiteSpace(ctx.Command.Description))
{
return false;
}

ctx.HelpBuilder.WriteHeading(LocalizationResources.HelpDescriptionTitle(), ctx.Command.Description, ctx.Output);
return true;
};
Expand Down