private string GetArgOrPrompt(
            string argValue,
            string name,
            string description,
            string defaultValue,
            Func <string, bool> validator)
        {
            // Check for the arg in the command line parser.
            ArgUtil.NotNull(validator, nameof(validator));
            string result = GetArg(argValue, name);

            // Return the arg if it is not empty and is valid.
            _trace.Info($"Arg '{name}': '{result}'");
            if (!string.IsNullOrEmpty(result))
            {
                if (validator(result))
                {
                    return(result);
                }

                _trace.Info("Arg is invalid.");
            }

            // Otherwise prompt for the arg.
            return(_promptManager.ReadValue(
                       argName: name,
                       description: description,
                       secret: Constants.Agent.CommandLine.Args.Secrets.Any(x => string.Equals(x, name, StringComparison.OrdinalIgnoreCase)),
                       defaultValue: defaultValue,
                       validator: validator,
                       unattended: Unattended()));
        }
Exemple #2
0
        private string GetArgOrPrompt(
            string name,
            string description,
            string defaultValue,
            Func <string, bool> validator,
            bool isOptional = false)
        {
            // Check for the arg in the command line parser.
            ArgUtil.NotNull(validator, nameof(validator));
            string result = GetArg(name);

            // Return the arg if it is not empty and is valid.
            _trace.Info($"Arg '{name}': '{result}'");
            if (!string.IsNullOrEmpty(result))
            {
                // After read the arg from input commandline args, remove it from Arg dictionary,
                // This will help if bad arg value passed through CommandLine arg, when ConfigurationManager ask CommandSetting the second time,
                // It will prompt for input instead of continue use the bad input.
                _trace.Info($"Remove {name} from Arg dictionary.");
                RemoveArg(name);

                if (validator(result))
                {
                    return(result);
                }

                _trace.Info("Arg is invalid.");
            }

            // Otherwise prompt for the arg.
            return(_promptManager.ReadValue(
                       argName: name,
                       description: description,
                       secret: Constants.Runner.CommandLine.Args.Secrets.Any(x => string.Equals(x, name, StringComparison.OrdinalIgnoreCase)),
                       defaultValue: defaultValue,
                       validator: validator,
                       unattended: Unattended,
                       isOptional: isOptional));
        }