Beispiel #1
0
        /// <summary>
        /// Initializes an instance of <see cref="InteractiveMode"/>.
        /// </summary>
        public InteractiveMode(IOptions <InteractiveModeOptions> options,
                               IConsole console,
                               ILogger <InteractiveMode> logger,
                               IRootSchemaAccessor rootSchemaAccessor,
                               ApplicationMetadata metadata,
                               ApplicationConfiguration configuration,
                               IServiceProvider serviceProvider)
        {
            _options = options.Value;

            _console         = console;
            _logger          = logger;
            _metadata        = metadata;
            _configuration   = configuration;
            _serviceProvider = serviceProvider;

            if (_options.IsAdvancedInputAvailable && !_console.Input.IsRedirected)
            {
                _autoCompleteInput = new AutoCompleteInput(_console, _options.UserDefinedShortcuts)
                {
                    AutoCompletionHandler = new AutoCompletionHandler(rootSchemaAccessor),
                };

                _autoCompleteInput.History.IsEnabled = true;
            }
        }
        /// <summary>
        /// Sets interactive mode prompt to action that directly interacts with console and has a DI resolvable service dependency.
        /// It is recommended to use <see cref="InteractiveModeOptions.PromptForeground"/> and <see cref="InteractiveModeOptions.ScopeForeground"/>.
        /// </summary>
        public static InteractiveModeOptions SetPrompt <TDep>(
            this InteractiveModeOptions options,
            Action <TDep, InteractiveModeOptions, ApplicationMetadata, IConsole> prompt)
            where TDep : notnull
        {
            options.SetPrompt((provider, metadata, console) =>
            {
                TDep dep = provider.GetRequiredService <TDep>();

                prompt(dep, options, metadata, console);
            });

            return(options);
        }
        /// <summary>
        /// Sets interactive mode prompt to action that directly interacts with console and has a DI resolvable service dependency.
        /// It is recommended to use <see cref="InteractiveModeOptions.PromptForeground"/> and <see cref="InteractiveModeOptions.ScopeForeground"/>.
        /// </summary>
        public static InteractiveModeOptions SetPrompt <TDep1, TDep2>(
            this InteractiveModeOptions options,
            Action <TDep1, TDep2, ApplicationMetadata, IConsole> prompt)
            where TDep1 : notnull
            where TDep2 : notnull
        {
            options.SetPrompt((provider, metadata, console) =>
            {
                TDep1 dep1 = provider.GetRequiredService <TDep1>();
                TDep2 dep2 = provider.GetRequiredService <TDep2>();

                prompt(dep1, dep2, metadata, console);
            });

            return(options);
        }