2020-01-24 13:48:16 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Diagnostics;
|
2021-07-08 07:56:31 +00:00
|
|
|
|
using System.Linq;
|
2021-09-04 09:33:59 +00:00
|
|
|
|
using System.Reflection;
|
2020-01-24 13:48:16 +00:00
|
|
|
|
using CommandLine;
|
2021-09-04 09:33:59 +00:00
|
|
|
|
using Tapeti.Cmd.Verbs;
|
2020-01-24 13:48:16 +00:00
|
|
|
|
|
|
|
|
|
namespace Tapeti.Cmd
|
|
|
|
|
{
|
|
|
|
|
public class Program
|
|
|
|
|
{
|
|
|
|
|
public static int Main(string[] args)
|
|
|
|
|
{
|
2021-09-04 09:33:59 +00:00
|
|
|
|
var exitCode = 1;
|
|
|
|
|
var verbTypes = Assembly.GetExecutingAssembly().GetTypes()
|
|
|
|
|
.Where(t => t.GetCustomAttribute<ExecutableVerbAttribute>() != null)
|
|
|
|
|
.ToArray();
|
2021-07-08 07:56:31 +00:00
|
|
|
|
|
2021-09-04 09:33:59 +00:00
|
|
|
|
CommandLine.Parser.Default.ParseArguments(args, verbTypes.ToArray())
|
|
|
|
|
.WithParsed(o =>
|
2021-07-08 07:56:31 +00:00
|
|
|
|
{
|
2021-09-04 09:33:59 +00:00
|
|
|
|
try
|
2020-03-29 09:32:51 +00:00
|
|
|
|
{
|
2021-09-04 09:33:59 +00:00
|
|
|
|
var executableVerbAttribute = o.GetType().GetCustomAttribute<ExecutableVerbAttribute>();
|
|
|
|
|
var executer = Activator.CreateInstance(executableVerbAttribute.VerbExecuter, o) as IVerbExecuter;
|
|
|
|
|
|
|
|
|
|
// Should have been validated by the ExecutableVerbAttribute
|
|
|
|
|
Debug.Assert(executer != null, nameof(executer) + " != null");
|
|
|
|
|
|
|
|
|
|
executer.Execute();
|
|
|
|
|
exitCode = 0;
|
2021-07-08 07:56:31 +00:00
|
|
|
|
}
|
2021-09-04 09:33:59 +00:00
|
|
|
|
catch (Exception e)
|
2021-07-08 07:56:31 +00:00
|
|
|
|
{
|
2021-09-04 09:33:59 +00:00
|
|
|
|
Console.WriteLine(e.Message);
|
|
|
|
|
DebugConfirmClose();
|
2021-07-08 07:56:31 +00:00
|
|
|
|
}
|
2021-09-04 09:33:59 +00:00
|
|
|
|
})
|
|
|
|
|
.WithNotParsed(_ =>
|
|
|
|
|
{
|
|
|
|
|
DebugConfirmClose();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return exitCode;
|
2021-07-08 11:44:16 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2021-09-04 09:33:59 +00:00
|
|
|
|
private static void DebugConfirmClose()
|
2021-07-08 11:44:16 +00:00
|
|
|
|
{
|
2021-09-04 09:33:59 +00:00
|
|
|
|
if (!Debugger.IsAttached)
|
|
|
|
|
return;
|
2021-07-08 11:44:16 +00:00
|
|
|
|
|
2021-09-04 09:33:59 +00:00
|
|
|
|
Console.WriteLine("Press any Enter key to continue...");
|
|
|
|
|
Console.ReadLine();
|
2021-07-08 11:44:16 +00:00
|
|
|
|
}
|
2020-01-24 13:48:16 +00:00
|
|
|
|
}
|
|
|
|
|
}
|