Пример #1
0
        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);
        }
Пример #2
0
        private static void ComposeDependencies(ref IConsoleManager consoleManager, ref IPreferences preferences, out HttpState state, out Shell shell)
        {
            consoleManager = consoleManager ?? new ConsoleManager();
            IFileSystem fileSystem = new RealFileSystem();

            preferences = preferences ?? new UserFolderPreferences(fileSystem, new UserProfileDirectoryProvider(), CreateDefaultPreferences());
            var httpClient = GetHttpClientWithPreferences(preferences);

            state = new HttpState(fileSystem, preferences, httpClient);

            var dispatcher = DefaultCommandDispatcher.Create(state.GetPrompt, state);

            dispatcher.AddCommand(new ChangeDirectoryCommand());
            dispatcher.AddCommand(new ClearCommand());
            dispatcher.AddCommand(new ConnectCommand(preferences));
            dispatcher.AddCommand(new DeleteCommand(fileSystem, preferences));
            dispatcher.AddCommand(new EchoCommand());
            dispatcher.AddCommand(new ExitCommand());
            dispatcher.AddCommand(new HeadCommand(fileSystem, preferences));
            dispatcher.AddCommand(new HelpCommand(preferences));
            dispatcher.AddCommand(new GetCommand(fileSystem, preferences));
            dispatcher.AddCommand(new ListCommand(preferences));
            dispatcher.AddCommand(new OptionsCommand(fileSystem, preferences));
            dispatcher.AddCommand(new PatchCommand(fileSystem, preferences));
            dispatcher.AddCommand(new PrefCommand(preferences));
            dispatcher.AddCommand(new PostCommand(fileSystem, preferences));
            dispatcher.AddCommand(new PutCommand(fileSystem, preferences));
            dispatcher.AddCommand(new RunCommand(fileSystem));
            dispatcher.AddCommand(new SetBaseCommand());
            dispatcher.AddCommand(new SetHeaderCommand());
            dispatcher.AddCommand(new UICommand(new UriLauncher(), preferences));

            shell = new Shell(dispatcher, consoleManager: consoleManager);
        }
Пример #3
0
        private static void ComposeDependencies(ref IConsoleManager consoleManager, ref IPreferences preferences, ref ITelemetry telemetry, out HttpState state, out Shell shell)
        {
            consoleManager ??= new ConsoleManager();
            IFileSystem fileSystem = new RealFileSystem();

            preferences ??= new UserFolderPreferences(fileSystem, new UserProfileDirectoryProvider(), CreateDefaultPreferences());
            telemetry ??= new Telemetry.Telemetry(VersionSensor.AssemblyInformationalVersion);
            HttpClient httpClient = GetHttpClientWithPreferences(preferences);

            state = new HttpState(preferences, httpClient);

            DefaultCommandDispatcher <HttpState> dispatcher = DefaultCommandDispatcher.Create(state.GetPrompt, state);

            dispatcher.AddCommandWithTelemetry(telemetry, new ChangeDirectoryCommand());
            dispatcher.AddCommandWithTelemetry(telemetry, new ClearCommand());
            dispatcher.AddCommandWithTelemetry(telemetry, new ConnectCommand(preferences, telemetry));
            dispatcher.AddCommandWithTelemetry(telemetry, new DeleteCommand(fileSystem, preferences, telemetry));
            dispatcher.AddCommandWithTelemetry(telemetry, new EchoCommand());
            dispatcher.AddCommandWithTelemetry(telemetry, new ExitCommand());
            dispatcher.AddCommandWithTelemetry(telemetry, new HeadCommand(fileSystem, preferences, telemetry));
            dispatcher.AddCommandWithTelemetry(telemetry, new HelpCommand());
            dispatcher.AddCommandWithTelemetry(telemetry, new GetCommand(fileSystem, preferences, telemetry));
            dispatcher.AddCommandWithTelemetry(telemetry, new ListCommand(preferences));
            dispatcher.AddCommandWithTelemetry(telemetry, new OptionsCommand(fileSystem, preferences, telemetry));
            dispatcher.AddCommandWithTelemetry(telemetry, new PatchCommand(fileSystem, preferences, telemetry));
            dispatcher.AddCommandWithTelemetry(telemetry, new PrefCommand(preferences, telemetry));
            dispatcher.AddCommandWithTelemetry(telemetry, new PostCommand(fileSystem, preferences, telemetry));
            dispatcher.AddCommandWithTelemetry(telemetry, new PutCommand(fileSystem, preferences, telemetry));
            dispatcher.AddCommandWithTelemetry(telemetry, new RunCommand(fileSystem));
            dispatcher.AddCommandWithTelemetry(telemetry, new SetHeaderCommand(telemetry));
            dispatcher.AddCommandWithTelemetry(telemetry, new UICommand(new UriLauncher(), preferences));

            shell = new Shell(dispatcher, consoleManager: consoleManager);
        }