private IShellState GetShellState(string inputBuffer, HttpState httpState) { DefaultCommandDispatcher <HttpState> defaultCommandDispatcher = DefaultCommandDispatcher.Create(x => { }, httpState); defaultCommandDispatcher.AddCommand(new SetHeaderCommand()); Mock <IConsoleManager> mockConsoleManager = new Mock <IConsoleManager>(); MockInputManager mockInputManager = new MockInputManager(inputBuffer); ShellState shellState = new ShellState(defaultCommandDispatcher, consoleManager: mockConsoleManager.Object, commandHistory: new CommandHistory(), inputManager: mockInputManager); Shell shell = new Shell(shellState); return(shell.ShellState); }
private Shell CreateShell(ConsoleKeyInfo consoleKeyInfo, string previousCommand, string nextCommand, out CancellationTokenSource cancellationTokenSource) { var defaultCommandDispatcher = DefaultCommandDispatcher.Create(x => { }, new object()); cancellationTokenSource = new CancellationTokenSource(); MockConsoleManager mockConsoleManager = new MockConsoleManager(consoleKeyInfo, cancellationTokenSource); Mock <ICommandHistory> mockCommandHistory = new Mock <ICommandHistory>(); mockCommandHistory.Setup(s => s.GetPreviousCommand()) .Returns(previousCommand); mockCommandHistory.Setup(s => s.GetNextCommand()) .Returns(nextCommand); ShellState shellState = new ShellState(defaultCommandDispatcher, consoleManager: mockConsoleManager, commandHistory: mockCommandHistory.Object); return(new Shell(shellState)); }
static async Task Main(string[] args) { var state = new HttpState(); if (Console.IsOutputRedirected) { Reporter.Error.WriteLine("Cannot start the REPL when output is being redirected".SetColor(state.ErrorColor)); return; } var dispatcher = DefaultCommandDispatcher.Create(state.GetPrompt, state); dispatcher.AddCommand(new ChangeDirectoryCommand()); dispatcher.AddCommand(new ClearCommand()); //dispatcher.AddCommand(new ConfigCommand()); dispatcher.AddCommand(new DeleteCommand()); dispatcher.AddCommand(new EchoCommand()); dispatcher.AddCommand(new ExitCommand()); dispatcher.AddCommand(new HeadCommand()); dispatcher.AddCommand(new HelpCommand()); dispatcher.AddCommand(new GetCommand()); dispatcher.AddCommand(new ListCommand()); dispatcher.AddCommand(new OptionsCommand()); dispatcher.AddCommand(new PatchCommand()); dispatcher.AddCommand(new PrefCommand()); dispatcher.AddCommand(new PostCommand()); dispatcher.AddCommand(new PutCommand()); dispatcher.AddCommand(new RunCommand()); dispatcher.AddCommand(new SetBaseCommand()); dispatcher.AddCommand(new SetDiagCommand()); dispatcher.AddCommand(new SetHeaderCommand()); dispatcher.AddCommand(new SetSwaggerCommand()); dispatcher.AddCommand(new UICommand()); CancellationTokenSource source = new CancellationTokenSource(); var shell = new Shell(dispatcher); shell.ShellState.ConsoleManager.AddBreakHandler(() => source.Cancel()); if (args.Length > 0) { if (string.Equals(args[0], "--help", StringComparison.OrdinalIgnoreCase)) { shell.ShellState.ConsoleManager.WriteLine("Usage: dotnet httprepl [<BASE_ADDRESS>] [options]"); shell.ShellState.ConsoleManager.WriteLine(); shell.ShellState.ConsoleManager.WriteLine("Arguments:"); shell.ShellState.ConsoleManager.WriteLine(" <BASE_ADDRESS> - The initial base address for the REPL."); shell.ShellState.ConsoleManager.WriteLine(); shell.ShellState.ConsoleManager.WriteLine("Options:"); shell.ShellState.ConsoleManager.WriteLine(" --help - Show help information."); shell.ShellState.ConsoleManager.WriteLine(); shell.ShellState.ConsoleManager.WriteLine("REPL Commands:"); new HelpCommand().CoreGetHelp(shell.ShellState, (ICommandDispatcher <HttpState, ICoreParseResult>)shell.ShellState.CommandDispatcher, state); return; } shell.ShellState.CommandDispatcher.OnReady(shell.ShellState); shell.ShellState.InputManager.SetInput(shell.ShellState, $"set base \"{args[0]}\""); await shell.ShellState.CommandDispatcher.ExecuteCommandAsync(shell.ShellState, CancellationToken.None).ConfigureAwait(false); } Task result = shell.RunAsync(source.Token); await result.ConfigureAwait(false); }
/// <summary> /// Initializes a new instance of the class. /// </summary> /// <param name="panelClass">the panel class of this scanner</param> /// <param name="panelTitle">The title of the menu</param> public WindowPosSizeContextMenu(String panelClass, String panelTitle) : base(panelClass, panelTitle) { _dispatcher = new DefaultCommandDispatcher(this); }
/// <summary> /// Initializes a new instance of the class. /// </summary> /// <param name="panelClass">the panel class of this scanner</param> /// <param name="panelTitle">The title of the menu</param> public DualMonitorMenu(String panelClass, String panelTitle) : base(panelClass, panelTitle) { _dispatcher = new DefaultCommandDispatcher(this); }
public static void AddCommandWithTelemetry(this DefaultCommandDispatcher <HttpState, ICoreParseResult> defaultCommandDispatcher, ITelemetry telemetry, ICommand <HttpState, ICoreParseResult> command) { defaultCommandDispatcher.AddCommand(new TelemetryCommandWrapper(telemetry, command)); }