You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
using DotWhat.Contracts;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Cocona;
|
|
|
|
|
|
|
|
|
|
namespace DotWhat
|
|
|
|
|
{
|
|
|
|
|
class Program
|
|
|
|
|
{
|
|
|
|
|
private static readonly IEnumerable<What> Whats =
|
|
|
|
|
Assembly.GetExecutingAssembly()
|
|
|
|
|
.GetTypes()
|
|
|
|
|
.Where(type => type.BaseType == typeof(What))
|
|
|
|
|
.Select(what => (What)Activator.CreateInstance(what));
|
|
|
|
|
|
|
|
|
|
private static async Task<int> Main(string[] args)
|
|
|
|
|
{
|
|
|
|
|
await CoconaLiteApp.RunAsync<Program>(args);
|
|
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public async Task StartAsync([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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await command.RunAsync();
|
|
|
|
|
|
|
|
|
|
static void PrintWhats()
|
|
|
|
|
=> Whats.ToList().ForEach(what => Console.WriteLine(what.Name.ToLower()));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|