protected static void Run(FakeApplicationBase app, string[] args, IConsoleAdapter console,
            IErrorAdapter errorAdapter)
        {
            app.Console = console;
            app.Error = errorAdapter;
            app.Initialise();
            app.PostInitialise();

            var commandLineInterpreter = new CommandLineInterpreter(app.Config);

            ConfigureHelpHandler(app, commandLineInterpreter);

            string[] errors;
            var command = commandLineInterpreter.Interpret(args, out errors, false);
            if (command == null)
            {
                if (errors != null)
                {
                    foreach (var error in errors)
                    {
                        app.Error.WrapLine(error);
                    }
                    Environment.ExitCode = app.CommandLineErrorExitCode;
                    return;
                }

                app._helpHandler.Execute(app, null, app.Console, app.Injector.Value, CommandExecutionMode.CommandLine);
                return;
            }

            ExecuteCommand(app, command, CommandExecutionMode.CommandLine);
        }
        public static string Do(CommandLineInterpreterConfiguration config, string[] commands, int width)
        {
            var sb = new StringBuilder();
            var interpreter = new CommandLineInterpreter(config);
            foreach (var command in commands)
            {
                sb.AppendLine(string.Format("Test: {0}", command));
                sb.AppendLine();

                var args = CommandLineTokeniser.Tokenise(command);
                string[] errors;
                var result = interpreter.Interpret(args, out errors, false);
                if (errors != null &&errors.Any())
                {
                    foreach (var e in errors)
                    {
                        sb.AppendLine(e);
                    }
                }
                else
                {
                    DisplayType(sb, result);
                }

                sb.AppendLine();
                sb.AppendLine();
            }

            return sb.ToString();
        }
        public static int Execute(string[] args, TextWriter output, int consoleWidth)
        {
            var config = ConfigureCommandLine();

            var interpreter = new CommandLineInterpreter(config);
            string[] errors;
            var options = interpreter.Interpret(args, out errors) as Options;
            if (options == null)
            {
                foreach (var error in errors)
                {
                    output.WriteLine(error);
                    output.WriteLine();
                    output.WriteLine(config.Describe(consoleWidth));
                    return -1;
                }
            }

            return Controller.Process(options, output);
        }