Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -5,7 +5,7 @@ Usage:
the-root-command [options] <the-root-arg-no-description-no-default> [<the-root-arg-no-description-default> <the-root-arg-no-default> [<the-root-arg> [<the-root-arg-enum-default>]]]

Arguments:
<the-root-arg-no-description-no-default>
<the-root-arg-no-description-no-default>
<the-root-arg-no-description-default> [default: the-root-arg-no-description-default-value]
<the-root-arg-no-default> the-root-arg-no-default-description
<the-root-arg> the-root-arg-description [default: the-root-arg-one-value]
Expand Down
150 changes: 112 additions & 38 deletions src/System.CommandLine.Tests/Help/HelpBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,9 @@ public void Synopsis_section_properly_wraps_description()
public void Command_name_in_synopsis_can_be_specified()
{
var command = new RootCommand
{
Name = "custom-name"
};
{
Name = "custom-name"
};

var helpBuilder = GetHelpBuilder(SmallMaxWidth);
helpBuilder.Write(command);
Expand All @@ -138,10 +138,10 @@ public void Usage_section_shows_arguments_if_there_are_arguments_for_command_whe
string expectedDescriptor)
{
var argument = new Argument
{
Name = "the-args",
Arity = new ArgumentArity(minArity, maxArity)
};
{
Name = "the-args",
Arity = new ArgumentArity(minArity, maxArity)
};
var command = new Command("the-command", "command help")
{
argument,
Expand Down Expand Up @@ -178,18 +178,18 @@ public void Usage_section_shows_arguments_if_there_are_arguments_for_command_whe
string expectedDescriptor)
{
var arg1 = new Argument
{
Name = "arg1",
Arity = new ArgumentArity(
minArityForArg1,
maxArityForArg1)
};
{
Name = "arg1",
Arity = new ArgumentArity(
minArityForArg1,
maxArityForArg1)
};
var arg2 = new Argument
{
Name = "arg2",
Arity = new ArgumentArity(
minArityForArg2,
maxArityForArg2)
{
Name = "arg2",
Arity = new ArgumentArity(
minArityForArg2,
maxArityForArg2)
};
var command = new Command("the-command", "command help")
{
Expand Down Expand Up @@ -426,7 +426,7 @@ public void Usage_section_does_not_contain_hidden_argument()
var command = new Command(commandName, "Does things");
var hiddenArg = new Argument<int>
{
Name = "hidden",
Name = "hidden",
IsHidden = true
};
var visibleArg = new Argument<int>
Expand All @@ -442,7 +442,7 @@ public void Usage_section_does_not_contain_hidden_argument()
var expected =
$"Usage:{NewLine}" +
$"{_indentation}{commandName} <{visibleArgName}>{NewLine}{NewLine}";

_console.Out.ToString().Should().Contain(expected);
}

Expand All @@ -465,7 +465,7 @@ public void Arguments_section_is_not_included_if_there_are_commands_but_no_argum

_helpBuilder.Write(command);
_console.Out.ToString().Should().NotContain("Arguments:");

_helpBuilder.Write(command);
_console.Out.ToString().Should().NotContain("Arguments:");
}
Expand Down Expand Up @@ -534,7 +534,7 @@ public void Arguments_section_includes_configured_argument_aliases()
Description = "Sets the verbosity."
}
};

_helpBuilder.Write(command);

var help = _console.Out.ToString();
Expand Down Expand Up @@ -589,14 +589,14 @@ public void Arguments_section_does_not_contain_hidden_argument()

var expected =
$"Arguments:{NewLine}" +
$"{_indentation}<{visibleArgName}>{_columnPadding}{visibleDesc}{NewLine}{NewLine}";
$"{_indentation}<{visibleArgName}>{_columnPadding}{visibleDesc}{NewLine}{NewLine}";

_helpBuilder.Write(command);
var help = _console.Out.ToString();

help.Should().Contain(expected);
help.Should().NotContain(hiddenArgName);
help.Should().NotContain(hiddenDesc);
help.Should().NotContain(hiddenDesc);
}

[Fact]
Expand Down Expand Up @@ -736,6 +736,34 @@ public void Arguments_section_properly_wraps_description()
_console.Out.ToString().Should().Contain(expected);
}

[Fact]
public void Arguments_section_properly_wraps()
{
var name = "argument-name-for-a-command-that-is-long-enough-to-wrap-to-a-new-line";
var description = "Argument description for a command with line breaks that is long enough to wrap to a new line.";

var command = new RootCommand()
{
new Argument
{
Name = name,
Description = description
}
};

HelpBuilder helpBuilder = GetHelpBuilder(SmallMaxWidth);
helpBuilder.Write(command);

var expected =
$"Arguments:{NewLine}" +
$"{_indentation}<argument-name-for-a-command-th{_columnPadding}Argument description for a{NewLine}" +
$"{_indentation}at-is-long-enough-to-wrap-to-a-{_columnPadding}command with line breaks that{NewLine}" +
$"{_indentation}new-line> {_columnPadding}is long enough to wrap to a new{NewLine}" +
$"{_indentation} {_columnPadding}line.{NewLine}{NewLine}";

_console.Out.ToString().Should().Contain(expected);
}

[Theory]
[InlineData(typeof(bool))]
[InlineData(typeof(bool?))]
Expand Down Expand Up @@ -813,10 +841,10 @@ public void Option_argument_descriptor_is_empty_for_boolean_values(Type type)
HelpBuilder helpBuilder = GetHelpBuilder(SmallMaxWidth);

helpBuilder.Write(command);

_console.Out.ToString().Should().Contain($"--opt{_columnPadding}{description}");
}

[Theory]
[InlineData(typeof(FileAccess))]
[InlineData(typeof(FileAccess?))]
Expand Down Expand Up @@ -947,7 +975,7 @@ public void Options_section_does_not_contain_option_with_HelpDefinition_that_IsH
{
IsHidden = false
});


_helpBuilder.Write(command);

Expand Down Expand Up @@ -1084,6 +1112,29 @@ public void Options_section_properly_wraps_description()
_console.Out.ToString().Should().Contain(expected);
}

[Fact]
public void Options_section_properly_wraps()
{
var alias = "--option-alias-for-a-command-that-is-long-enough-to-wrap-to-a-new-line";
var description = "Option description that is long enough to wrap.";

var command = new RootCommand()
{
new Option(alias, description)
};

HelpBuilder helpBuilder = GetHelpBuilder(SmallMaxWidth);
helpBuilder.Write(command);

var expected =
$"Options:{NewLine}" +
$"{_indentation}--option-alias-for-a-command-th{_columnPadding}Option description that is long{NewLine}" +
$"{_indentation}at-is-long-enough-to-wrap-to-a-{_columnPadding}enough to wrap.{NewLine}" +
$"{_indentation}new-line{NewLine}{NewLine}";

_console.Out.ToString().Should().Contain(expected);
}

[Fact]
public void Options_section_does_not_contain_hidden_argument()
{
Expand Down Expand Up @@ -1126,13 +1177,13 @@ public void Required_options_are_indicated()
};

_helpBuilder.Write(command);

var help = _console.Out.ToString();

help.Should()
.Contain("--required (REQUIRED)");
}

[Fact]
public void Required_options_are_indicated_when_argument_is_named()
{
Expand All @@ -1146,7 +1197,7 @@ public void Required_options_are_indicated_when_argument_is_named()
};

_helpBuilder.Write(command);

var help = _console.Out.ToString();

help.Should()
Expand Down Expand Up @@ -1177,12 +1228,12 @@ public void Options_aliases_differing_only_by_prefix_are_deduplicated_favoring_d
};

_helpBuilder.Write(command);

var help = _console.Out.ToString();

help.Should().NotContain("/x");
}

[Fact]
public void Options_aliases_differing_only_by_prefix_are_deduplicated_favoring_double_dashed_prefixes()
{
Expand All @@ -1192,7 +1243,7 @@ public void Options_aliases_differing_only_by_prefix_are_deduplicated_favoring_d
};

_helpBuilder.Write(command);

var help = _console.Out.ToString();

help.Should().NotContain("/long");
Expand Down Expand Up @@ -1265,7 +1316,7 @@ public void Help_describes_default_value_for_option_with_argument_having_default
}

[Fact]
public void Help_should_not_contain_default_value_for_hidden_argument_defined_for_option ()
public void Help_should_not_contain_default_value_for_hidden_argument_defined_for_option()
{
var argument = new Argument
{
Expand Down Expand Up @@ -1427,7 +1478,7 @@ public void Subcommands_properly_wraps_description()
}
};

helpBuilder.Write(command);
helpBuilder.Write(command);

var expected =
$"Commands:{NewLine}" +
Expand All @@ -1437,6 +1488,29 @@ public void Subcommands_properly_wraps_description()
_console.Out.ToString().Should().Contain(expected);
}

[Fact]
public void Subcommands_section_properly_wraps()
{
var name = "subcommand-name-that-is-long-enough-to-wrap-to-a-new-line";
var description = "Subcommand description that is really long. So long that it caused the line to wrap.";

var command = new RootCommand()
{
new Command(name, description)
};

var helpBuilder = GetHelpBuilder(SmallMaxWidth);
helpBuilder.Write(command);

var expected =
$"Commands:{NewLine}" +
$"{_indentation}subcommand-name-that-is-long-en{_columnPadding}Subcommand description that is{NewLine}" +
$"{_indentation}ough-to-wrap-to-a-new-line {_columnPadding}really long. So long that it{NewLine}" +
$"{_indentation} {_columnPadding}caused the line to wrap.{NewLine}{NewLine}";

_console.Out.ToString().Should().Contain(expected);
}

[Fact]
public void Subcommand_help_contains_command_with_empty_description()
{
Expand Down Expand Up @@ -1479,12 +1553,12 @@ public void Subcommand_help_does_not_contain_hidden_argument()
var subCommand = new Command("the-subcommand");
var hidden = new Argument<int>()
{
Name = "the-hidden",
Name = "the-hidden",
IsHidden = true
};
var visible = new Argument<int>()
{
Name = "the-visible",
Name = "the-visible",
IsHidden = false
};
subCommand.AddArgument(hidden);
Expand Down Expand Up @@ -1557,7 +1631,7 @@ public void Help_describes_default_value_for_subcommand_with_arguments_and_only_
}

[Fact]
public void Help_describes_default_values_for_subcommand_with_multiple_defaultable_arguments ()
public void Help_describes_default_values_for_subcommand_with_multiple_defaultable_arguments()
{
var argument = new Argument
{
Expand Down
Loading