Пример #1
0
        private void ParseProperties(IEnumerable <ArgumentMap> argumentsMaps, bool enablePositionalArgs, ParseResult.CommandParse commandParse, IEnumerable <ArgumentRaw> argumentsRaw)
        {
            var parseds = this.argumentParser.Parse(argumentsRaw, enablePositionalArgs, argumentsMaps);

            commandParse.AddProperties(parseds.Where(f => f.ParsingStates.HasFlag(ArgumentParsedState.Valid)));

            // Don't considere invalid args in this situation:
            // -> ArgumentMappingType.HasNoInput && ArgumentMappingState.ArgumentIsNotRequired
            // "ArgumentMappingType.HasNoInput": Means that args don't have input.
            // "ArgumentMappingState.ArgumentIsNotRequired": Means that args is optional.
            // in this situation the args is not consider invalid.
            commandParse.AddPropertiesInvalid(parseds.Where(f => f.ParsingStates.HasFlag(ArgumentParsedState.IsInvalid) && !f.ParsingStates.HasFlag(ArgumentParsedState.ArgumentIsNotRequired)));
        }
Пример #2
0
        private ParseResult.Level GetLevelWithPropertiesDefaultOrRequired(IEnumerable <ParseResult.Level> levels, IEnumerable <CommandMap> map)
        {
            ParseResult.Level level = null;

            var properties        = levels.SelectMany(l => l.Commands.SelectMany(c => c.Properties));
            var propertiesInvalid = levels.SelectMany(l => l.Commands.SelectMany(c => c.PropertiesInvalid));
            var listMapsRequiredOrDefaultNotMapped = new Dictionary <CommandBase, List <ArgumentMap> >();

            foreach (var cmd in map)
            {
                foreach (var propMap in cmd.Properties)
                {
                    if (propMap.HasDefaultValue || !propMap.IsOptional)
                    {
                        var notExistsInInvalid = propertiesInvalid.Empty(f => f.Map == propMap);
                        var notExistsInValid   = properties.Empty(f => f.Map == propMap);
                        if (notExistsInInvalid && notExistsInValid)
                        {
                            if (!listMapsRequiredOrDefaultNotMapped.ContainsKey(cmd.Command))
                            {
                                listMapsRequiredOrDefaultNotMapped[cmd.Command] = new List <ArgumentMap>();
                            }

                            listMapsRequiredOrDefaultNotMapped[cmd.Command].Add(propMap);
                        }
                    }
                }
            }

            if (listMapsRequiredOrDefaultNotMapped.Any())
            {
                level = new ParseResult.Level();

                foreach (var keyValue in listMapsRequiredOrDefaultNotMapped)
                {
                    var defaultsOrRequireds = argumentParser.CreateArgumentsDefaultValueOrRequired(keyValue.Value);
                    argumentParser.SetState(defaultsOrRequireds);

                    var commandParse = new ParseResult.CommandParse();
                    commandParse.Command = keyValue.Key;
                    commandParse.AddProperties(defaultsOrRequireds.Where(f => f.ParsingType == ArgumentParsedType.DefaultValue));
                    commandParse.AddPropertiesInvalid(defaultsOrRequireds.Where(f => f.ParsingType == ArgumentParsedType.HasNoInput));
                    level.Add(commandParse);
                }
            }

            return(level);
        }