mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
Change format for the command section in help text (#83)
This commit is contained in:
@@ -65,7 +65,7 @@ namespace CliFx.Tests
|
|||||||
}
|
}
|
||||||
|
|
||||||
[Fact]
|
[Fact]
|
||||||
public async Task Help_text_shows_usage_format_which_lists_available_sub_commands()
|
public async Task Help_text_shows_commands_list_with_description_and_usage_info()
|
||||||
{
|
{
|
||||||
// Arrange
|
// Arrange
|
||||||
var (console, stdOut, _) = VirtualConsole.CreateBuffered();
|
var (console, stdOut, _) = VirtualConsole.CreateBuffered();
|
||||||
@@ -78,14 +78,16 @@ namespace CliFx.Tests
|
|||||||
.Build();
|
.Build();
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
var exitCode = await application.RunAsync(new[] {"--help"});
|
var exitCode = await application.RunAsync(new[] { "--help" });
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
exitCode.Should().Be(0);
|
exitCode.Should().Be(0);
|
||||||
stdOut.GetString().Should().ContainAll(
|
stdOut.GetString().Should().ContainAll(
|
||||||
"Usage",
|
"Commands",
|
||||||
"... named",
|
"Named command description",
|
||||||
"... named sub"
|
"named [options]",
|
||||||
|
"Named sub command description",
|
||||||
|
"named sub [options]"
|
||||||
);
|
);
|
||||||
|
|
||||||
_output.WriteLine(stdOut.GetString());
|
_output.WriteLine(stdOut.GetString());
|
||||||
|
|||||||
@@ -169,19 +169,6 @@ namespace CliFx.Domain
|
|||||||
|
|
||||||
// Current command usage
|
// Current command usage
|
||||||
WriteCommandUsageLineItem(command, childCommands.Any());
|
WriteCommandUsageLineItem(command, childCommands.Any());
|
||||||
|
|
||||||
// Sub commands usage
|
|
||||||
if (childCommands.Any())
|
|
||||||
{
|
|
||||||
WriteVerticalMargin();
|
|
||||||
|
|
||||||
foreach (var childCommand in childCommands)
|
|
||||||
{
|
|
||||||
WriteHorizontalMargin();
|
|
||||||
Write("... ");
|
|
||||||
WriteCommandUsageLineItem(childCommand, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WriteCommandParameters(CommandSchema command)
|
private void WriteCommandParameters(CommandSchema command)
|
||||||
@@ -298,9 +285,9 @@ namespace CliFx.Domain
|
|||||||
|
|
||||||
private void WriteCommandChildren(
|
private void WriteCommandChildren(
|
||||||
CommandSchema command,
|
CommandSchema command,
|
||||||
IReadOnlyList<CommandSchema> childCommands)
|
IReadOnlyList<CommandSchema> descendantCommands)
|
||||||
{
|
{
|
||||||
if (!childCommands.Any())
|
if (!descendantCommands.Any())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!IsEmpty)
|
if (!IsEmpty)
|
||||||
@@ -308,28 +295,29 @@ namespace CliFx.Domain
|
|||||||
|
|
||||||
WriteHeader("Commands");
|
WriteHeader("Commands");
|
||||||
|
|
||||||
foreach (var childCommand in childCommands)
|
foreach (var descendantCommand in descendantCommands)
|
||||||
{
|
{
|
||||||
var relativeCommandName = !string.IsNullOrWhiteSpace(command.Name)
|
var relativeCommandName = !string.IsNullOrWhiteSpace(command.Name)
|
||||||
? childCommand.Name!.Substring(command.Name.Length).Trim()
|
? descendantCommand.Name!.Substring(command.Name.Length).Trim()
|
||||||
: childCommand.Name!;
|
: descendantCommand.Name!;
|
||||||
|
|
||||||
// Name
|
|
||||||
WriteHorizontalMargin();
|
|
||||||
Write(ConsoleColor.Cyan, relativeCommandName);
|
|
||||||
|
|
||||||
// Description
|
// Description
|
||||||
if (!string.IsNullOrWhiteSpace(childCommand.Description))
|
|
||||||
|
if (!string.IsNullOrWhiteSpace(descendantCommand.Description))
|
||||||
{
|
{
|
||||||
WriteColumnMargin();
|
WriteHorizontalMargin();
|
||||||
Write(childCommand.Description);
|
Write(descendantCommand.Description);
|
||||||
|
WriteVerticalMargin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Name
|
||||||
|
WriteHorizontalMargin(4);
|
||||||
|
WriteCommandUsageLineItem(descendantCommand, false);
|
||||||
|
|
||||||
WriteLine();
|
WriteLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Child command help tip
|
// Child command help tip
|
||||||
WriteVerticalMargin();
|
|
||||||
Write("You can run `");
|
Write("You can run `");
|
||||||
Write(_metadata.ExecutableName);
|
Write(_metadata.ExecutableName);
|
||||||
|
|
||||||
@@ -356,7 +344,6 @@ namespace CliFx.Domain
|
|||||||
IReadOnlyDictionary<CommandArgumentSchema, object?> defaultValues)
|
IReadOnlyDictionary<CommandArgumentSchema, object?> defaultValues)
|
||||||
{
|
{
|
||||||
var commandName = command.Name;
|
var commandName = command.Name;
|
||||||
var childCommands = root.GetChildCommands(commandName);
|
|
||||||
var descendantCommands = root.GetDescendantCommands(commandName);
|
var descendantCommands = root.GetDescendantCommands(commandName);
|
||||||
|
|
||||||
_console.ResetColor();
|
_console.ResetColor();
|
||||||
@@ -368,7 +355,7 @@ namespace CliFx.Domain
|
|||||||
WriteCommandUsage(command, descendantCommands);
|
WriteCommandUsage(command, descendantCommands);
|
||||||
WriteCommandParameters(command);
|
WriteCommandParameters(command);
|
||||||
WriteCommandOptions(command, defaultValues);
|
WriteCommandOptions(command, defaultValues);
|
||||||
WriteCommandChildren(command, childCommands);
|
WriteCommandChildren(command, descendantCommands);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user