Beispiel #1
0
        /// <summary>
        /// Parses input before pipeline execution.
        /// </summary>
        protected virtual async Task <int> ParseInput(IReadOnlyList <string> commandLineArguments,
                                                      RootSchema root)
        {
            //TODO: CommandInput.Parse as middleware step
            CommandInput input = CommandInputResolver.Parse(commandLineArguments, root.GetCommandNames());

            CliContext.Input = input;

            return(await ExecuteCommand());
        }
        protected override async Task <int> ParseInput(IReadOnlyList <string> commandLineArguments,
                                                       RootSchema root)
        {
            CommandInput input = CommandInputResolver.Parse(commandLineArguments, root.GetCommandNames());

            CliContext.Input = input;

            if (input.IsInteractiveDirectiveSpecified)
            {
                CliContext.IsInteractiveMode = true;

                // we don't want to run default command for e.g. `[interactive]` but we want to run if there is sth else
                if (!input.IsDefaultCommandOrEmpty)
                {
                    await ExecuteCommand();
                }

                await RunInteractivelyAsync(root);

                return(ExitCodes.Success); // called after Ctrl+C
            }

            return(await ExecuteCommand());
        }
        private async Task RunInteractivelyAsync(RootSchema root)
        {
            IConsole console        = CliContext.Console;
            string   executableName = CliContext.Metadata.ExecutableName;

            do
            {
                string[]? commandLineArguments = GetInput(console, executableName);

                if (commandLineArguments is null)
                {
                    console.ResetColor();
                    return;
                }

                CommandInput input = CommandInputResolver.Parse(commandLineArguments, root.GetCommandNames());
                CliContext.Input = input; //TODO maybe refactor with some clever IDisposable class

                await ExecuteCommand();

                console.ResetColor();
            }while (!console.GetCancellationToken().IsCancellationRequested);
        }