forked from BeyondDimension/SteamTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.Main.cs
More file actions
45 lines (40 loc) · 1.34 KB
/
Program.Main.cs
File metadata and controls
45 lines (40 loc) · 1.34 KB
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
43
44
45
using System;
using System.CommandLine;
using System.Linq;
using System.Reflection;
static partial class Program
{
static int _(string[] args,
string description = "",
Assembly? assembly = null,
string @namespace = "System.Application.Steps",
string methodName = "Add",
Func<int?>? init = null,
Action<RootCommand>? action = null)
{
try
{
var result = init?.Invoke();
if (result.HasValue) return result.Value;
var rootCommand = new RootCommand(description);
action?.Invoke(rootCommand);
var steps = (assembly ?? Assembly.GetCallingAssembly()).GetTypes()
.Where(x => x.Namespace == @namespace && x.IsClass && !x.IsGenericType && x.IsAbstract && x.IsSealed);
foreach (var step in steps)
{
var method = step.GetMethod(methodName, BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(RootCommand) }, null);
method?.Invoke(null, new[] { rootCommand });
}
return rootCommand.InvokeAsync(args).Result;
}
catch (Exception? e)
{
while (e != null)
{
Console.WriteLine(e.ToString());
e = e.InnerException;
}
return 500;
}
}
}