/// <summary>
 /// Registers the unique switch with the parser.
 /// </summary>
 /// <exception cref="ArgumentException">Switch cannot be null.</exception>
 public void AddSwitch(CommandSwitch sw)
 {
     if (sw == null)
     {
         throw new ArgumentException("Switch cannot be null.");
     }
     _switches.Add(sw);
 }
Exemple #2
0
            internal void AddSwitch(CommandSwitch csw)
            {
                if (_switches == null)
                {
                    _switches = new List <ParseResultSwitch.Builder>();
                }
                var found = _switches.Find(x => x.csw == csw);

                if (found == null)
                {
                    _last = new ParseResultSwitch.Builder(csw);
                    _switches.Add(_last);
                }
                else
                {
                    _last = found;
                }
            }
        private void AddStringSwitch(ref PathSplit psp, string value, string arg, ParseResult.Builder result)
        {
            CommandSwitch sw = FindSwitchIdentifiedBy(value);

            if (sw == null)
            {
                throw new InvalidInput("Invalid switch: " + value);
            }
            if (arg != null)
            {
                if (sw.arity != Arity.NoneOrOne)
                {
                    throw new InvalidInput($"Switch {value} has argument, which is not allowed for the given switch.");
                }
                result.AddSwitch(sw);

                if ((sw.arity == Arity.One || sw.arity == Arity.NoneOrOne) && result.AlreadyHasArgumentForLastSwitch())
                {
                    throw new InvalidInput($"Switch {value} can accept only one argument, but two are supplied.");
                }
                result.AddArgForLastSwitch(arg);
                psp = PathSplit.Maybe;
            }
            else
            {
                switch (sw.arity)
                {
                case Arity.None:                psp = PathSplit.Maybe; break;

                case Arity.One:                 psp = PathSplit.NotForOne; break;

                case Arity.NoneOrOne:   psp = PathSplit.Maybe; break;

                case Arity.Any:         psp = PathSplit.Not; break;

                default: throw new Termination("Should not reach this.");
                }
                result.AddSwitch(sw);
            }
        }
Exemple #4
0
 internal Builder(CommandSwitch csw)
 {
     this.csw = csw;
 }