public void GetNextCommand_Test() { var target = new CommandSourceCollection(); target.AddToEnd(new QueueCommandSource("test1")); target.AddToEnd(new QueueCommandSource("test2")); target.GetNextCommand().String.Should().Be("test1"); target.GetNextCommand().String.Should().Be("test2"); target.GetNextCommand().Should().Be(null); }
/// <summary> /// Runs interactively, setting the environment to the value given and then /// prompting the user for commands to execute. Returns when the user has entered /// the 'exit' or 'quit' commands, or when some other verb has set the exit /// condition. /// </summary> /// <param name="environment"></param> public int RunInteractively(string environment) { SetupState(false); var source = new CommandSourceCollection(); // Change the environment if necessary. Otherwise the EngineStartInteractive // script will probably prompt the user to do so. if (!string.IsNullOrEmpty(environment)) { source.AddToEnd($"{EnvironmentHandler.Name} '{environment}'"); } source.AddToEnd(_state.EventCatalog.EngineStartInteractive, _parser); source.AddToEnd(new PromptCommandSource(Output, Environments, _state)); return(RunLoop(source)); }
/// <summary> /// Run the application in headless mode with the provided commandline string. /// </summary> /// <param name="commandLine"></param> /// <returns></returns> public int RunHeadless(string commandLine) { SetupState(true); var sources = new CommandSourceCollection(); // If we have a single argument "help", run the help script and exit. We don't // require a valid environment to run help if (commandLine == "help") { sources.AddToEnd(_state.EventCatalog.HeadlessHelp, _parser, ("exitcode", Constants.ExitCodeHeadlessHelp.ToString()) ); return(RunLoop(sources)); } // Now see if the first argument is the name of an environment. If so, switch // to that environment and continue var(startingEnvironment, newCl) = GetStartingEnvironment(commandLine); commandLine = newCl; // If there is no commandline left, run the HeadlessNoArgs script if (string.IsNullOrWhiteSpace(commandLine)) { sources.AddToEnd(_state.EventCatalog.HeadlessNoArgs, _parser, ("exitcode", Constants.ExitCodeHeadlessNoVerb.ToString()) ); return(RunLoop(sources)); } // Setup the Headless start script, an environment change command if any, the // user command, and the headless stop script sources.AddToEnd(_state.EventCatalog.EngineStartHeadless, _parser); if (!string.IsNullOrWhiteSpace(startingEnvironment)) { sources.AddToEnd($"{EnvironmentHandler.Name} '{startingEnvironment}'"); } sources.AddToEnd(commandLine); sources.AddToEnd(_state.EventCatalog.EngineStopHeadless, _parser); return(RunLoop(sources)); }
public void GetNextCommand_Empty() { var target = new CommandSourceCollection(); target.GetNextCommand().Should().Be(null); }