mirror of
https://github.com/nsnail/spectre.console.git
synced 2025-04-16 17:02:51 +08:00
Added "--hidden" param to explain feature
Probably shouldn't include the hidden commands by default. This lets the user show them if needed.
This commit is contained in:
parent
ae96606ab7
commit
bc9f610258
@ -22,10 +22,11 @@ namespace Spectre.Console.Cli
|
|||||||
|
|
||||||
public sealed class Settings : CommandSettings
|
public sealed class Settings : CommandSettings
|
||||||
{
|
{
|
||||||
public Settings(string[]? commands, bool? detailed)
|
public Settings(string[]? commands, bool? detailed, bool includeHidden)
|
||||||
{
|
{
|
||||||
Commands = commands;
|
Commands = commands;
|
||||||
Detailed = detailed;
|
Detailed = detailed;
|
||||||
|
IncludeHidden = includeHidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
[CommandArgument(0, "[command]")]
|
[CommandArgument(0, "[command]")]
|
||||||
@ -34,6 +35,10 @@ namespace Spectre.Console.Cli
|
|||||||
[Description("Include detailed information about the commands.")]
|
[Description("Include detailed information about the commands.")]
|
||||||
[CommandOption("-d|--detailed")]
|
[CommandOption("-d|--detailed")]
|
||||||
public bool? Detailed { get; }
|
public bool? Detailed { get; }
|
||||||
|
|
||||||
|
[Description("Include hidden commands.")]
|
||||||
|
[CommandOption("--hidden")]
|
||||||
|
public bool IncludeHidden { get; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override int Execute([NotNull] CommandContext context, [NotNull] Settings settings)
|
public override int Execute([NotNull] CommandContext context, [NotNull] Settings settings)
|
||||||
@ -52,7 +57,8 @@ namespace Spectre.Console.Cli
|
|||||||
AddCommands(
|
AddCommands(
|
||||||
tree.AddNode(ParentMarkup("Commands")),
|
tree.AddNode(ParentMarkup("Commands")),
|
||||||
commands,
|
commands,
|
||||||
settings.Detailed ?? false);
|
settings.Detailed ?? false,
|
||||||
|
settings.IncludeHidden);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -82,7 +88,8 @@ namespace Spectre.Console.Cli
|
|||||||
AddCommands(
|
AddCommands(
|
||||||
tree.AddNode(ParentMarkup("Commands")),
|
tree.AddNode(ParentMarkup("Commands")),
|
||||||
new[] { currentCommand },
|
new[] { currentCommand },
|
||||||
settings.Detailed ?? true);
|
settings.Detailed ?? true,
|
||||||
|
settings.IncludeHidden);
|
||||||
}
|
}
|
||||||
|
|
||||||
_writer.Write(tree);
|
_writer.Write(tree);
|
||||||
@ -126,10 +133,15 @@ namespace Spectre.Console.Cli
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddCommands(TreeNode node, IEnumerable<CommandInfo> commands, bool detailed)
|
private void AddCommands(TreeNode node, IEnumerable<CommandInfo> commands, bool detailed, bool includeHidden)
|
||||||
{
|
{
|
||||||
foreach (var command in commands)
|
foreach (var command in commands)
|
||||||
{
|
{
|
||||||
|
if (!includeHidden && command.IsHidden)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
var commandName = $"[green]{command.Name}[/]";
|
var commandName = $"[green]{command.Name}[/]";
|
||||||
if (command.IsDefaultCommand)
|
if (command.IsDefaultCommand)
|
||||||
{
|
{
|
||||||
@ -164,7 +176,7 @@ namespace Spectre.Console.Cli
|
|||||||
if (command.Children.Count > 0)
|
if (command.Children.Count > 0)
|
||||||
{
|
{
|
||||||
var childNode = commandNode.AddNode(ParentMarkup("Child Commands"));
|
var childNode = commandNode.AddNode(ParentMarkup("Child Commands"));
|
||||||
AddCommands(childNode, command.Children, detailed);
|
AddCommands(childNode, command.Children, detailed, includeHidden);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user