using Cocona; using DotWhat.Contracts; using System; using System.Collections.Generic; using System.Linq; using System.Reflection; using System.Threading.Tasks; namespace DotWhat { internal class Program { private static readonly IEnumerable Whats = Assembly.GetExecutingAssembly() .GetTypes() .Where(type => type.BaseType == typeof(What)) .Select(what => (What?)Activator.CreateInstance(what)); private static async Task Main(string[] args) { await CoconaLiteApp.RunAsync(args).ConfigureAwait(false); return 0; } public void Start([Argument] string? name = default) { if (string.IsNullOrEmpty(name)) { Console.WriteLine("No what passed. Current available whats are:"); PrintWhats(); return; } var command = Whats.FirstOrDefault(what => what!.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); if (command is null) { Console.WriteLine("Invalid what passed. Current available whats are:"); PrintWhats(); return; } command.Run(); static void PrintWhats() => Whats.ToList().ForEach(what => Console.WriteLine(what!.Name.ToLower())); } } }