mirror of
https://github.com/Tyrrrz/CliFx.git
synced 2025-10-25 15:19:17 +00:00
Add child command usage in help text (#77)
This commit is contained in:
@@ -105,31 +105,52 @@ namespace CliFx.Domain
|
|||||||
WriteLine();
|
WriteLine();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void WriteCommandUsage(CommandSchema command, IReadOnlyList<CommandSchema> childCommands)
|
private void WriteCommandUsage(
|
||||||
|
CommandSchema command,
|
||||||
|
IReadOnlyList<CommandSchema> childCommands)
|
||||||
{
|
{
|
||||||
if (!IsEmpty)
|
if (!IsEmpty)
|
||||||
WriteVerticalMargin();
|
WriteVerticalMargin();
|
||||||
|
|
||||||
WriteHeader("Usage");
|
WriteHeader("Usage");
|
||||||
|
|
||||||
// Exe name
|
WriteCommandUsageLineItem(command, childCommands.Count > 0);
|
||||||
WriteHorizontalMargin();
|
|
||||||
Write(_metadata.ExecutableName);
|
|
||||||
|
|
||||||
|
if (!IsEmpty)
|
||||||
|
WriteVerticalMargin();
|
||||||
|
|
||||||
|
foreach (var childCommand in childCommands)
|
||||||
|
{
|
||||||
|
WriteCommandUsageLineItem(childCommand, compactCommand: false, size: 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WriteCommandUsageLineItem(
|
||||||
|
CommandSchema command,
|
||||||
|
bool compactCommand = true,
|
||||||
|
int size = 2)
|
||||||
|
{
|
||||||
|
WriteHorizontalMargin(size);
|
||||||
|
if (compactCommand)
|
||||||
|
{
|
||||||
|
// Exe name
|
||||||
|
Write(_metadata.ExecutableName);
|
||||||
|
Write(' ');
|
||||||
|
|
||||||
|
}
|
||||||
// Command name
|
// Command name
|
||||||
if (!string.IsNullOrWhiteSpace(command.Name))
|
if (!string.IsNullOrWhiteSpace(command.Name))
|
||||||
{
|
{
|
||||||
Write(' ');
|
// this is fragile, because we rely that subcommand name consists
|
||||||
|
// of all required tokens
|
||||||
Write(ConsoleColor.Cyan, command.Name);
|
Write(ConsoleColor.Cyan, command.Name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Child command placeholder
|
// Child command placeholder
|
||||||
if (childCommands.Any())
|
if (compactCommand)
|
||||||
{
|
{
|
||||||
Write(' ');
|
Write(' ');
|
||||||
Write(ConsoleColor.Cyan, "[command]");
|
Write(ConsoleColor.Cyan, "[command]");
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parameters
|
// Parameters
|
||||||
foreach (var parameter in command.Parameters)
|
foreach (var parameter in command.Parameters)
|
||||||
{
|
{
|
||||||
@@ -334,7 +355,9 @@ namespace CliFx.Domain
|
|||||||
CommandSchema command,
|
CommandSchema command,
|
||||||
IReadOnlyDictionary<CommandArgumentSchema, object?> defaultValues)
|
IReadOnlyDictionary<CommandArgumentSchema, object?> defaultValues)
|
||||||
{
|
{
|
||||||
var childCommands = root.GetChildCommands(command.Name);
|
var commandName = command.Name;
|
||||||
|
var childCommands = root.GetChildCommands(commandName);
|
||||||
|
var descendantCommands = root.GetDescendantCommands(commandName);
|
||||||
|
|
||||||
_console.ResetColor();
|
_console.ResetColor();
|
||||||
|
|
||||||
@@ -342,7 +365,7 @@ namespace CliFx.Domain
|
|||||||
WriteApplicationInfo();
|
WriteApplicationInfo();
|
||||||
|
|
||||||
WriteCommandDescription(command);
|
WriteCommandDescription(command);
|
||||||
WriteCommandUsage(command, childCommands);
|
WriteCommandUsage(command, descendantCommands);
|
||||||
WriteCommandParameters(command);
|
WriteCommandParameters(command);
|
||||||
WriteCommandOptions(command, defaultValues);
|
WriteCommandOptions(command, defaultValues);
|
||||||
WriteCommandChildren(command, childCommands);
|
WriteCommandChildren(command, childCommands);
|
||||||
|
|||||||
Reference in New Issue
Block a user