public string AskUserForValue()

in src/AWS.Deploy.CLI/ConsoleUtilities.cs [337:391]


        public string AskUserForValue(string message, string defaultValue, bool allowEmpty, string resetValue = "", string? defaultAskValuePrompt = null, params Func<string, Task<string>>[] validators)
        {
            const string RESET = "<reset>";
            var prompt = !string.IsNullOrEmpty(defaultAskValuePrompt) ? defaultAskValuePrompt : "Enter value";
            if (!string.IsNullOrEmpty(defaultValue))
                prompt += $" (default {defaultValue}";

            if (!string.IsNullOrEmpty(message))
                _interactiveService.WriteLine(message);

            if (allowEmpty)
                prompt += $". Type {RESET} to reset.";
            prompt += "): ";
            _interactiveService.WriteLine(prompt);

            string? userValue = null;
            while (true)
            {
                var line = _interactiveService.ReadLine()?.Trim() ?? "";

                if (allowEmpty &&
                    (string.Equals(RESET, line.Trim(), StringComparison.OrdinalIgnoreCase) ||
                     string.Equals($"'{RESET}'", line.Trim(), StringComparison.OrdinalIgnoreCase)))
                {
                    return resetValue;
                }

                if (string.IsNullOrEmpty(line) && !string.IsNullOrEmpty(defaultValue))
                {
                    return defaultValue;
                }

                userValue = line;

                if (!string.IsNullOrEmpty(defaultValue) && string.IsNullOrEmpty(userValue))
                   continue;

                var errorMessages =
                      validators
                            .Select(async v => await v(userValue))
                            .Select(v => v.Result)
                            .Where(e => !string.IsNullOrEmpty(e))
                            .ToList();

                if (errorMessages.Any())
                {
                    _interactiveService.WriteErrorLine(errorMessages.First());
                    continue;
                }

                break;
            }

            return userValue;
        }