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();
        }
        private static void ConfigureHelpHandler(FakeApplicationBase app, CommandLineInterpreter commandLineInterpreter)
        {
            if (app._helpHandler == null)
                app._helpHandler = new HelpHandler(null, null, app.Config);

            app._helpHandler.Adorner = commandLineInterpreter.GetOptionNameAdorner();
        }
        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 void ConfigurationShouldBeDescribed()
 {
     var interpreter = new CommandLineInterpreter(_posix);
     CommandDescriber.Describe(_posix, _console, _applicationName, CommandExecutionMode.CommandLine, interpreter.GetOptionNameAdorner());
     var description = _consoleOutInterface.GetBuffer();
     Console.WriteLine(description);
     Approvals.Verify(description);
 }
 public InteractiveSession(ConsoleApplicationBase app, MethodParameterInjector injector, Dictionary<Type, ICommandHandler> handlers, IConsoleAdapter console, IErrorAdapter error, CommandLineInterpreterConfiguration config)
 {
     _app = app;
     _injector = injector;
     _handlers = handlers;
     _console = console;
     _error = error;
     _config = config;
     _interpreter = new CommandLineInterpreter(_config);
 }
        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);
        }