/// <summary> /// The entry point for the command line application. /// </summary> /// <param name="args"></param> /// <param name="logger"></param> /// <param name="helper"></param> /// <param name="appGenerator"></param> /// <returns></returns> public static int ExecuteCommand(string[] args, Func <IConsoleInterface, ICommandLineConsoleLogger> logger = null, Func <IConsoleWriter, ICommandLineHelpGenerator> helper = null, Func <IConsole, ICommandLineConsoleLogger, ICommandLineHelpGenerator, CommandLineApplicationPlus <TModel> > appGenerator = null) { var console = new CommandLineConsoleInterface(); var consoleLogger = logger?.Invoke(console) ?? new CommandLineConsoleLogger(console); var helpGenerator = helper?.Invoke(consoleLogger) ?? new CommandLineHelpGenerator(consoleLogger); try { using (var app = appGenerator?.Invoke(console, consoleLogger, helpGenerator) ?? new CommandLineApplicationPlus <TModel>(helpGenerator, console, consoleLogger, Directory.GetCurrentDirectory())) { return(app.ExecuteCommandInternal(args)); } } catch (Exception ex) { consoleLogger.LogTheshold = ConsoleLogThreshold.Debug; consoleLogger.Error(ex.Message, ex); consoleLogger.Fatal($"Exit code {AExecutionCommand.FatalExitCode}"); consoleLogger.WriteOnNewLine(null); return(AExecutionCommand.FatalExitCode); } finally { consoleLogger.Dispose(); } }
/// <inheritdoc /> protected CommandLineApplicationPlus(IHelpTextGenerator helpTextGenerator, CommandLineConsoleInterface console, ICommandLineConsoleLogger consoleLogger, string workingDirectory) : base(helpTextGenerator, console, workingDirectory) { Console = console; ConsoleLogger = consoleLogger; }