-
Notifications
You must be signed in to change notification settings - Fork 0
/
Program.cs
42 lines (37 loc) · 1.23 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
namespace twot
{
using System;
using System.Collections.Generic;
using System.CommandLine;
using System.Linq;
using System.Reflection;
public class Program
{
public static int Main(string[] args)
{
EnableUTFConsole();
var rootCommand = new RootCommand("Twot: Making Twitter Better");
foreach (var command in GetCommands())
{
command.AddCommand(rootCommand);
}
Console.WriteLine();
return rootCommand.InvokeAsync(args).Result;
}
private static IEnumerable<ICommand> GetCommands()
{
#pragma warning disable SA1009
return Assembly.GetAssembly(typeof(Program))!.GetTypes()
#pragma warning restore SA1009
.Where(t => typeof(ICommand).IsAssignableFrom(t))
.Where(t => t.IsClass)
.Select(commandInterface => Activator.CreateInstance(commandInterface) as ICommand)
.Select(commandObject => commandObject!);
}
private static void EnableUTFConsole()
{
Console.OutputEncoding = System.Text.Encoding.UTF8;
Console.Write("\xfeff"); // bom = byte order mark
}
}
}