Beispiel #1
0
        /// <inheritdoc />
        public ValidationResult GetValidationResult(CommandOption option, ValidationContext context)
        {
            if (option.HasValue())
            {
                return(ValidationResult.Success);
            }
            var varName = $"{_rootApplication.Name}_{option.LongName}".ToUpper();
            var environmentVariables = Environment.GetEnvironmentVariables();

            if (environmentVariables.Contains(varName))
            {
                _command?.DebugLogFromSetOptionValueFromEnvironmentVariable.Add($"Setting option --{option.LongName} with the value of the environment variable {varName}.");
                option.TryParse(environmentVariables[varName] as string);
                if (_property != null)
                {
                    var parser = _application.ValueParsers.GetParser(_property.PropertyType);
                    var value  = parser.Parse(option.LongName, environmentVariables[varName] as string, CultureInfo.CurrentCulture);
                    StaticUtilities.SetPropertyValue(_property, _command, value);
                }
            }
            return(ValidationResult.Success);
        }