public CommandOption( Type parameterType, ParameterKind parameterKind, PropertyInfo property, string?description, TypeConverterAttribute?converter, PairDeconstructorAttribute?deconstructor, CommandOptionAttribute optionAttribute, IEnumerable <ParameterValidationAttribute> validators, DefaultValueAttribute?defaultValue, bool valueIsOptional) : base(parameterType, parameterKind, property, description, converter, defaultValue, deconstructor, validators, false) { LongNames = optionAttribute.LongNames; ShortNames = optionAttribute.ShortNames; ValueName = optionAttribute.ValueName; ValueIsOptional = valueIsOptional; }
public CommandTreeParser(CommandModel configuration, ICommandAppSettings settings, ParsingMode?parsingMode = null) { if (settings is null) { throw new ArgumentNullException(nameof(settings)); } _configuration = configuration; _parsingMode = parsingMode ?? _configuration.ParsingMode; _help = new CommandOptionAttribute("-h|--help"); CaseSensitivity = settings.CaseSensitivity; }
private static ParameterKind GetOptionKind( Type type, CommandOptionAttribute attribute, PairDeconstructorAttribute?deconstructor, TypeConverterAttribute?converter) { if (attribute.ValueIsOptional) { return(ParameterKind.FlagWithValue); } if (type.IsPairDeconstructable() && (deconstructor != null || converter == null)) { return(ParameterKind.Pair); } return(GetParameterKind(type)); }
private static CommandOption BuildOptionParameter(PropertyInfo property, CommandOptionAttribute attribute) { var description = property.GetCustomAttribute <DescriptionAttribute>(); var converter = property.GetCustomAttribute <TypeConverterAttribute>(); var deconstructor = property.GetCustomAttribute <PairDeconstructorAttribute>(); var validators = property.GetCustomAttributes <ParameterValidationAttribute>(true); var defaultValue = property.GetCustomAttribute <DefaultValueAttribute>(); var kind = GetOptionKind(property.PropertyType, attribute, deconstructor, converter); if (defaultValue == null && property.PropertyType == typeof(bool)) { defaultValue = new DefaultValueAttribute(false); } return(new CommandOption(property.PropertyType, kind, property, description?.Description, converter, deconstructor, attribute, validators, defaultValue, attribute.ValueIsOptional)); }