namespace Spectre.Console.Cli; internal sealed class CommandModel : ICommandContainer { public string? ApplicationName { get; } public ParsingMode ParsingMode { get; } public IList Commands { get; } public IList Examples { get; } public bool TrimTrailingPeriod { get; } public CommandInfo? DefaultCommand => Commands.FirstOrDefault(c => c.IsDefaultCommand); public CommandModel( CommandAppSettings settings, IEnumerable commands, IEnumerable examples) { ApplicationName = settings.ApplicationName; ParsingMode = settings.ParsingMode; TrimTrailingPeriod = settings.TrimTrailingPeriod; Commands = new List(commands ?? Array.Empty()); Examples = new List(examples ?? Array.Empty()); } public string GetApplicationName() { return ApplicationName ?? Path.GetFileName(GetApplicationFile()) ?? // null is propagated by GetFileName "?"; } private static string? GetApplicationFile() { var location = Assembly.GetEntryAssembly()?.Location; if (string.IsNullOrWhiteSpace(location)) { // this is special case for single file executable // (Assembly.Location returns empty string) return Process.GetCurrentProcess().MainModule?.FileName; } return location; } }