WithType() 공개 메소드

public WithType ( OptionType newType ) : OptionBuilder
newType OptionType
리턴 OptionBuilder
예제 #1
0
        public static Options Parse(String pattern)
        {
            char       opt      = ' ';
            bool       required = false;
            OptionType type     = OptionType.None;

            Options options = new Options();

            for (int i = 0; i < pattern.Length; i++)
            {
                char ch = pattern[i];

                // a value code comes after an option and specifies
                // details about it
                if (!IsValueCode(ch))
                {
                    if (opt != ' ')
                    {
                        OptionBuilder builder = new OptionBuilder();
                        builder.HasArgument(type != OptionType.None);
                        builder.IsRequired(required);
                        builder.WithType(type);

                        // we have a previous one to deal with
                        options.AddOption(builder.Create(opt));
                        required = false;
                        type     = OptionType.None;
                        opt      = ' ';
                    }

                    opt = ch;
                }
                else if (ch == '!')
                {
                    required = true;
                }
                else
                {
                    type = getValueClass(ch);
                }
            }

            if (opt != ' ')
            {
                OptionBuilder builder = new OptionBuilder();
                builder.HasArgument(type != OptionType.None);
                builder.IsRequired(required);
                builder.WithType(type);

                // we have a final one to deal with
                options.AddOption(builder.Create(opt));
            }

            return(options);
        }
예제 #2
0
        public static Options Parse(String pattern)
        {
            char opt = ' ';
            bool required = false;
            OptionType type = OptionType.None;

            Options options = new Options();

            for (int i = 0; i < pattern.Length; i++) {
                char ch = pattern[i];

                // a value code comes after an option and specifies
                // details about it
                if (!IsValueCode(ch)) {
                    if (opt != ' ') {
                        OptionBuilder builder = new OptionBuilder();
                        builder.HasArgument(type != OptionType.None);
                        builder.IsRequired(required);
                        builder.WithType(type);

                        // we have a previous one to deal with
                        options.AddOption(builder.Create(opt));
                        required = false;
                        type = OptionType.None;
                        opt = ' ';
                    }

                    opt = ch;
                } else if (ch == '!') {
                    required = true;
                } else {
                    type = getValueClass(ch);
                }
            }

            if (opt != ' ') {
                OptionBuilder builder = new OptionBuilder();
                builder.HasArgument(type != OptionType.None);
                builder.IsRequired(required);
                builder.WithType(type);

                // we have a final one to deal with
                options.AddOption(builder.Create(opt));
            }

            return options;
        }