Skip to content

Commit

Permalink
Hide hidden args from options and subcommand help
Browse files Browse the repository at this point in the history
  • Loading branch information
Icontech committed Jul 27, 2019
1 parent 4c9e5d6 commit 5cef484
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
56 changes: 56 additions & 0 deletions src/System.CommandLine.Tests/Help/HelpBuilderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1010,6 +1010,36 @@ public void Options_section_properly_wraps_description()
_console.Out.ToString().Should().Contain(expected);
}

[Fact]
public void Options_section_does_not_contain_hidden_argument()
{
var command = new Command("the-command", "Does things.");
var opt1 = new Option("option1")
{
Argument = new Argument<int>()
{
Name = "the-hidden",
IsHidden = true
}
};
var opt2 = new Option("option2")
{
Argument = new Argument<int>()
{
Name = "the-visible",
IsHidden = false
}
};
command.AddOption(opt1);
command.AddOption(opt2);

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

help.Should().NotContain("the-hidden");
help.Should().Contain("the-visible");
}

#endregion Options

#region Subcommands
Expand Down Expand Up @@ -1170,6 +1200,32 @@ public void Subcommand_help_does_not_contain_hidden_command()
help.Should().Contain("the-visible");
}

[Fact]
public void Subcommand_help_does_not_contain_hidden_argument()
{
var command = new Command("the-command", "Does things.");
var subCommand = new Command("the-subcommand");
var hidden = new Argument<int>()
{
Name = "the-hidden",
IsHidden = true
};
var visible = new Argument<int>()
{
Name = "the-visible",
IsHidden = false
};
subCommand.AddArgument(hidden);
subCommand.AddArgument(visible);
command.AddCommand(subCommand);

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

help.Should().NotContain("the-hidden");
help.Should().Contain("the-visible");
}

#endregion Subcommands
}
}
2 changes: 1 addition & 1 deletion src/System.CommandLine/Help/HelpBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ protected virtual IEnumerable<HelpItem> OptionFormatter(ISymbol symbol)
{
foreach (var argument in symbol.Arguments())
{
if (!string.IsNullOrWhiteSpace(argument.Name))
if (ShouldShowHelp(argument) && !string.IsNullOrWhiteSpace(argument.Name))
{
var argumentDescriptor = ArgumentDescriptor(argument);
if (!string.IsNullOrWhiteSpace(argumentDescriptor))
Expand Down

0 comments on commit 5cef484

Please sign in to comment.