namespace Spectre.Console.Cli; internal sealed class CommandInfo : ICommandContainer { public string Name { get; } public HashSet Aliases { get; } public string? Description { get; } public object? Data { get; } public Type? CommandType { get; } public Type SettingsType { get; } public Func? Delegate { get; } public bool IsDefaultCommand { get; } public CommandInfo? Parent { get; } public IList Children { get; } public IList Parameters { get; } public IList Examples { get; } public bool IsBranch => CommandType == null && Delegate == null; IList ICommandContainer.Commands => Children; // only branches can have a default command public CommandInfo? DefaultCommand => IsBranch ? Children.FirstOrDefault(c => c.IsDefaultCommand) : null; public bool IsHidden { get; } public CommandInfo(CommandInfo? parent, ConfiguredCommand prototype) { Parent = parent; Name = prototype.Name; Aliases = new HashSet(prototype.Aliases); Description = prototype.Description; Data = prototype.Data; CommandType = prototype.CommandType; SettingsType = prototype.SettingsType; Delegate = prototype.Delegate; IsDefaultCommand = prototype.IsDefaultCommand; IsHidden = prototype.IsHidden; Children = new List(); Parameters = new List(); Examples = prototype.Examples ?? new List(); if (CommandType != null && string.IsNullOrWhiteSpace(Description)) { var description = CommandType.GetCustomAttribute(); if (description != null) { Description = description.Description; } } } public List Flatten() { var result = new Stack(); var current = this; while (current != null) { result.Push(current); current = current.Parent; } return result.ToList(); } }