/// <summary> /// Initializes the specified application. /// </summary> /// <param name="app">The application.</param> /// <returns></returns> public static CustomCommandLineApplication Initialize(this CustomCommandLineApplication app) { AnsiConsole.GetError(true); app.HelpOption(HelpFlag); app.VersionOption(VersionFlag, Constants.ShortVersion, Constants.LongVersion); app.Name = Constants.Name; app.Description = Constants.ProgramHelpDescription; app.ExtendedHelpText = Constants.ExtendedHelpText; var methods = typeof(Command).GetMethods(BindingFlags.Public | BindingFlags.Static) .Where(c => c.Name != "Initialize").ToList(); methods = methods.Where(c => typeof(CustomCommandLineApplication).IsAssignableFrom(c.ReturnType) && c.GetParameters() is ParameterInfo[] u && u.Length == 1 && typeof(CommandLineApplication).IsAssignableFrom(u[0].ParameterType) ).ToList(); foreach (MethodInfo method in methods) { try { method.Invoke(null, new object[] { app }); } catch (Exception e) { if (System.Diagnostics.Debugger.IsAttached) { System.Diagnostics.Debugger.Break(); } throw; } } return(app); }