Пример #1
0
        public List <string> Parse(IEnumerable <string> arguments)
        {
            if (arguments.IsNull())
            {
                throw new ArgumentNullException("arguments");
            }

            OptionContext c = CreateOptionContext();

            c.OptionIndex = -1;
            bool               process     = true;
            List <string>      unprocessed = new List <string>();
            Option             def         = Contains("<>") ? this["<>"] : null;
            ArgumentEnumerator ae          = new ArgumentEnumerator(arguments);

            foreach (string argument in ae)
            {
                ++c.OptionIndex;

                if (argument == "--")
                {
                    process = false;
                    continue;
                }

                if (!process)
                {
                    Unprocessed(unprocessed, def, c, argument);
                    continue;
                }

                if (AddSource(ae, argument))
                {
                    continue;
                }

                if (!Parse(argument, c))
                {
                    Unprocessed(unprocessed, def, c, argument);
                }
            }

            if (!c.Option.IsNull())
            {
                c.Option.Invoke(c);
            }

            return(unprocessed);
        }
Пример #2
0
        bool AddSource(ArgumentEnumerator ae, string argument)
        {
            foreach (ArgumentSource source in sources)
            {
                IEnumerable <string> replacement;

                if (!source.GetArguments(argument, out replacement))
                {
                    continue;
                }

                ae.Add(replacement);
                return(true);
            }

            return(false);
        }