public async Task Start(string[] args, IConsoleManager consoleManager = null, IPreferences preferences = null) { args = args ?? throw new ArgumentNullException(nameof(args)); ComposeDependencies(ref consoleManager, ref preferences, out HttpState state, out Shell shell); if (Console.IsOutputRedirected && !consoleManager.AllowOutputRedirection) { Reporter.Error.WriteLine(Resources.Strings.Error_OutputRedirected.SetColor(preferences.GetColorValue(WellKnownPreference.ErrorColor))); return; } using (CancellationTokenSource source = new CancellationTokenSource()) { shell.ShellState.ConsoleManager.AddBreakHandler(() => source.Cancel()); if (args.Length > 0) { if (string.Equals(args[0], "--help", StringComparison.OrdinalIgnoreCase) || string.Equals(args[0], "-h", StringComparison.OrdinalIgnoreCase)) { shell.ShellState.ConsoleManager.WriteLine(Resources.Strings.Help_Usage); shell.ShellState.ConsoleManager.WriteLine(" dotnet httprepl [<BASE_ADDRESS>] [options]"); shell.ShellState.ConsoleManager.WriteLine(); shell.ShellState.ConsoleManager.WriteLine(Resources.Strings.Help_Arguments); shell.ShellState.ConsoleManager.WriteLine(string.Format(Resources.Strings.Help_BaseAddress, "<BASE_ADDRESS>")); shell.ShellState.ConsoleManager.WriteLine(); shell.ShellState.ConsoleManager.WriteLine(Resources.Strings.Help_Options); shell.ShellState.ConsoleManager.WriteLine(string.Format(Resources.Strings.Help_Help, "-h|--help")); shell.ShellState.ConsoleManager.WriteLine(); shell.ShellState.ConsoleManager.WriteLine(Resources.Strings.Help_REPLCommands); new HelpCommand(preferences).CoreGetHelp(shell.ShellState, (ICommandDispatcher <HttpState, ICoreParseResult>)shell.ShellState.CommandDispatcher, state); return; } // allow running a script file directly. if (string.Equals(args[0], "run", StringComparison.OrdinalIgnoreCase)) { shell.ShellState.CommandDispatcher.OnReady(shell.ShellState); shell.ShellState.InputManager.SetInput(shell.ShellState, string.Join(' ', args)); await shell.ShellState.CommandDispatcher.ExecuteCommandAsync(shell.ShellState, CancellationToken.None).ConfigureAwait(false); return; } string combinedArgs = string.Join(' ', args); shell.ShellState.CommandDispatcher.OnReady(shell.ShellState); shell.ShellState.InputManager.SetInput(shell.ShellState, $"connect {combinedArgs}"); await shell.ShellState.CommandDispatcher.ExecuteCommandAsync(shell.ShellState, CancellationToken.None).ConfigureAwait(false); } await shell.RunAsync(source.Token).ConfigureAwait(false); } }
public static async Task Start(string[] args, IConsoleManager consoleManager = null, IPreferences preferences = null, ITelemetry telemetry = null) { args = args ?? throw new ArgumentNullException(nameof(args)); RegisterEncodingProviders(); ComposeDependencies(ref consoleManager, ref preferences, ref telemetry, out HttpState state, out Shell shell); if (!telemetry.FirstTimeUseNoticeSentinel.Exists() && !Telemetry.Telemetry.SkipFirstTimeExperience) { Reporter.Output.WriteLine(string.Format(Resources.Strings.Telemetry_WelcomeMessage, VersionSensor.AssemblyVersion.ToString(2))); telemetry.FirstTimeUseNoticeSentinel.CreateIfNotExists(); } if (Console.IsOutputRedirected && !consoleManager.AllowOutputRedirection) { telemetry.TrackStartedEvent(withOutputRedirection: true); Reporter.Error.WriteLine(Resources.Strings.Error_OutputRedirected.SetColor(preferences.GetColorValue(WellKnownPreference.ErrorColor))); return; } using (CancellationTokenSource source = new CancellationTokenSource()) { shell.ShellState.ConsoleManager.AddBreakHandler(() => source.Cancel()); if (args.Length > 0) { if (string.Equals(args[0], "--help", StringComparison.OrdinalIgnoreCase) || string.Equals(args[0], "-h", StringComparison.OrdinalIgnoreCase)) { telemetry.TrackStartedEvent(withHelp: true); shell.ShellState.ConsoleManager.WriteLine(Resources.Strings.Help_Usage); shell.ShellState.ConsoleManager.WriteLine(" httprepl [<BASE_ADDRESS>] [options]"); shell.ShellState.ConsoleManager.WriteLine(); shell.ShellState.ConsoleManager.WriteLine(Resources.Strings.Help_Arguments); shell.ShellState.ConsoleManager.WriteLine(string.Format(Resources.Strings.Help_BaseAddress, "<BASE_ADDRESS>")); shell.ShellState.ConsoleManager.WriteLine(); shell.ShellState.ConsoleManager.WriteLine(Resources.Strings.Help_Options); shell.ShellState.ConsoleManager.WriteLine(string.Format(Resources.Strings.Help_Help, "-h|--help")); shell.ShellState.ConsoleManager.WriteLine(); shell.ShellState.ConsoleManager.WriteLine(Resources.Strings.Help_REPLCommands); HelpCommand.CoreGetHelp(shell.ShellState, (ICommandDispatcher <HttpState, ICoreParseResult>)shell.ShellState.CommandDispatcher, state); return; } // allow running a script file directly. if (string.Equals(args[0], "run", StringComparison.OrdinalIgnoreCase)) { telemetry.TrackStartedEvent(withRun: true); shell.ShellState.CommandDispatcher.OnReady(shell.ShellState); shell.ShellState.InputManager.SetInput(shell.ShellState, string.Join(' ', args)); await shell.ShellState.CommandDispatcher.ExecuteCommandAsync(shell.ShellState, CancellationToken.None).ConfigureAwait(false); return; } telemetry.TrackStartedEvent(withOtherArgs: args.Length > 0); string combinedArgs = string.Join(' ', args); shell.ShellState.CommandDispatcher.OnReady(shell.ShellState); shell.ShellState.InputManager.SetInput(shell.ShellState, $"connect {combinedArgs}"); await shell.ShellState.CommandDispatcher.ExecuteCommandAsync(shell.ShellState, CancellationToken.None).ConfigureAwait(false); } else { telemetry.TrackStartedEvent(); } await shell.RunAsync(source.Token).ConfigureAwait(false); } }