public int EntryPoint(string[] args) { try { string result = null; var connectorOptions = ConnectorOptions.Parse(args, out var commandArgs); if (connectorOptions.DebugMode && !Debugger.IsAttached) { Debugger.Launch(); } switch (connectorOptions.Command) { case DiscoveryCommand.CommandName: { result = DiscoveryCommand.Execute(commandArgs); break; } case GeneratorCommand.CommandName: { result = GeneratorCommand.Execute(commandArgs); break; } default: throw new ArgumentException($"Invalid command: {connectorOptions.Command}"); } if (result == null) { return(1); } Console.WriteLine(JsonSerialization.MarkResult(result)); return(0); } catch (Exception ex) { Console.Error.WriteLine($"Error: {GetExceptionMessage(ex)}"); Console.Error.WriteLine($"Exception: {GetExceptionTypes(ex)}"); Console.Error.WriteLine("StackTrace:"); Console.Error.WriteLine(GetStackTrace(ex)); return(ex is ArgumentException ? 3 : 4); } }
public static ConnectorOptions Parse(string[] args, out string[] commandArgs) { if (args == null || args.Length == 0) { throw new ArgumentException("Command is missing!"); } var options = new ConnectorOptions { Command = args[0] }; var commandArgsList = args.Skip(1).ToList(); int debugArgIndex = commandArgsList.IndexOf("--debug"); if (debugArgIndex >= 0) { options.DebugMode = true; commandArgsList.RemoveAt(debugArgIndex); } commandArgs = commandArgsList.ToArray(); return(options); }