Пример #1
0
        public ParseResult Parse(string text)
        {
            ParserContext context = new ParserContext(_configuration, text);

            AbstractState state = new InitialState(context);
            while (!state.IsTerminal)
            {
                state = state.Advance();
            }

            CheckForMissingRequiredParameters(context);

            return context.Result;
        }
Пример #2
0
        private void CheckForMissingRequiredParameters(ParserContext context)
        {
            if (context.Command != null)
            {
                var missing = context.Command.RemainingPositionalParameters.Where(x => x.IsRequired);

                foreach (var p in missing)
                {
                    bool ok = false;

                    if (p.IsCollection)
                    {
                        ok = context.Result.CommandListValues.Any(x => x.Name.Equals(p.Name, StringComparison.InvariantCultureIgnoreCase));
                    }

                    if (!ok)
                    {
                        context.Result.AddError("Required parameter '{0}' was not specified.", p.Name);
                    }
                }
            }
        }