public void Parse_OrderedCommandParser_HandlesSwitchesAndRoutesTheCommandCorrectly() { // Arrange var parser = new OrderedCommandParser(); var commandName = ""; parser.SetRoutes(_routing.GetRoutes()); // Act var param = parser.Parse("ls c:\\ProgramFiles *.csv /s /switch", out commandName); var route = _routing.FindRoute(commandName, param); // Assert Assert.AreEqual("ls", commandName); Assert.AreEqual(4, param.Count); // two param and 2 switches Assert.IsNotNull(route); Assert.AreEqual("ls", route.Name); }
private void Init(IParseCommands parser, IRouteCommands routing, IParseRoutes routeParser, ICmdRConsole console, ICmdRState state, string[] exitcodes = null, string cmdPrompt = "> ") { _state = state; _state.CmdPrompt = cmdPrompt; _state.Routes = routing.GetRoutes(); _state.ExitCodes = exitcodes ?? new string[] { "exit" }; _console = console; _commandParser = parser; _commandRouter = routing; _routeParser = routeParser; }
private void Init(IParseCommands parser, IRouteCommands routing, IParseRoutes routeParser, ICmdRConsole console, ICmdRState state, string[] exitcodes = null, string cmdPrompt = "> ") { _state = state; _state.CmdPrompt = cmdPrompt; _state.Routes = routing.GetRoutes(); _state.ExitCodes = exitcodes ?? new string[] { "exit" }; _console = console; _commandParser = parser; _commandRouter = routing; _routeParser = routeParser; }
public void ExecuteCommand(string command) { if (string.IsNullOrEmpty(command)) { return; } _commandParser.SetRoutes(_commandRouter.GetRoutes()); var commandName = ""; var parameters = _commandParser.Parse(command, out commandName); var route = _commandRouter.FindRoute(commandName, parameters); route.Execute(parameters, _console, _state); }