Inheritance: IOption
Ejemplo n.º 1
0
        public Options AddOption(Option option)
        {
            String key = option.Key();

            // add it to the long option list
            if (option.HasLongName()) {
                longOpts[option.LongName] = option;
            }

            // if the option is required add it to the required list
            if (option.IsRequired) {
                if (requiredOpts.Contains(key)) {
                    requiredOpts.RemoveAt(requiredOpts.IndexOf(key));
                }
                requiredOpts.Add(key);
            }

            shortOpts[key] = option;

            return this;
        }
Ejemplo n.º 2
0
        public Option Create(String opt)
        {
            Option option;
            try {
                // create the option
                option = new Option(opt, description);

                // set the option properties
                option.LongName = longopt;
                option.IsRequired = required;
                option.HasOptionalArgument = optionalArg;
                option.ArgumentCount = numberOfArgs;
                option.Type = type;
                option.ValueSeparator = valuesep;
                option.ArgumentName = argName;
            } finally {
                // reset the OptionBuilder properties
                Reset();
            }

            // return the Option instance
            return option;
        }
Ejemplo n.º 3
0
        public OptionGroup GetOptionGroup(Option opt)
        {
            OptionGroup group;
            if (optionGroups.TryGetValue(opt.Key(), out group))
                return group;

            return null;
        }
Ejemplo n.º 4
0
        private static Option CreateOptionFromMember(MemberInfo member, IDictionary<string, OptionGroup> groups)
        {
            var attribute = (OptionAttribute) Attribute.GetCustomAttribute(member, typeof(OptionAttribute));

            string optionName = null;
            string optionLongName = null;
            if (attribute != null) {
                optionLongName = attribute.LongName;
                optionName = attribute.Name;
            }

            if (String.IsNullOrEmpty(optionName))
                optionName = member.Name[0].ToString(CultureInfo.InvariantCulture);
            if (String.IsNullOrEmpty(optionLongName))
                optionLongName = member.Name;

            var desc = attribute != null ? attribute.Description : null;
            var option = new Option(optionName, desc) {
                LongName = optionLongName,
                ArgumentCount = attribute != null ? attribute.ArgumentCount : 0,
                IsRequired = attribute != null && attribute.IsRequired,
                ArgumentName = attribute != null ? attribute.ArgumentName : "arg",
                ValueSeparator = attribute != null ? attribute.ValueSeparator : ' ',
                HasOptionalArgument = attribute != null && attribute.HasOptionalArgument
            };

            var groupAttr = (OptionGroupAttribute)Attribute.GetCustomAttribute(member, typeof(OptionGroupAttribute));
            if (groupAttr != null) {
                OptionGroup group;
                if (!groups.TryGetValue(groupAttr.Name, out group)) {
                    group = new OptionGroup();
                    groups[groupAttr.Name] = group;
                }

                group.AddOption(option);
                return null;
            }

            return option;
        }