示例#1
0
文件: Parser.cs 项目: cj525/yaclops
        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
文件: Parser.cs 项目: cj525/yaclops
        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);
                    }
                }
            }
        }