private static IEnumerable<Match> MatchCommands(CommandParameters parameters, int argCount, CommandHandlerDescriptor descriptor, ICommandHandler handler)
 {
     foreach (var commandDescriptor in descriptor.Commands)
     {
         foreach (var name in commandDescriptor.Names)
         {
             var names = name.Split(' ');
             if (parameters.Arguments.Take(argCount).SequenceEqual(names, StringComparer.OrdinalIgnoreCase))
             {
                 yield return new Match
                 {
                     Context = new CommandContext
                     {
                         Arguments = parameters.Arguments.Skip(names.Count()),
                         Command = string.Join(" ", names),
                         CommandDescriptor = commandDescriptor,
                         Input = parameters.Input,
                         Output = parameters.Output,
                         Switches = parameters.Switches,
                     },
                     CommandHandler = handler
                 };
             }
         }
     }
 }
示例#2
0
        private static IEnumerable<Match> MatchCommands(CommandParameters parameters, int argCount, CommandHandlerDescriptor descriptor, ICommandHandler handler)
        {
            foreach (var commandDescriptor in descriptor.Commands)
            {
                foreach (var name in commandDescriptor.Names)
                {
                    var names = name.Split(' ');
                    // We check here number of arguments a command can recieve against
                    // arguments provided for the command to identify the correct command
                    // and avoid matching multiple commands.
                    if(commandDescriptor.MethodInfo.GetParameters().Length == argCount - names.Count())
                    {
                        names = parameters.Arguments.ToArray();
                    }

                    if (parameters.Arguments.Take(argCount).SequenceEqual(names, StringComparer.OrdinalIgnoreCase))
                    {
                        yield return new Match
                        {
                            Context = new CommandContext
                            {
                                Arguments = parameters.Arguments.Skip(name.Split(' ').Count()),
                                Command = string.Join(" ", names),
                                CommandDescriptor = commandDescriptor,
                                Input = parameters.Input,
                                Output = parameters.Output,
                                Switches = parameters.Switches,
                            },
                            CommandHandler = handler
                        };
                    }
                }
            }
        }
示例#3
0
        private static IEnumerable <Match> MatchCommands(CommandParameters parameters, int argCount, CommandHandlerDescriptor descriptor, ICommandHandler handler)
        {
            foreach (var commandDescriptor in descriptor.Commands)
            {
                var names = commandDescriptor.Name.Split(' ');
                if (!parameters.Arguments.Take(argCount).SequenceEqual(names, StringComparer.OrdinalIgnoreCase))
                {
                    // leading arguments not equal to command name
                    continue;
                }

                yield return(new Match {
                    Context = new CommandContext {
                        Arguments = parameters.Arguments.Skip(names.Count()),
                        Command = string.Join(" ", names),
                        CommandDescriptor = commandDescriptor,
                        Input = parameters.Input,
                        Output = parameters.Output,
                        Switches = parameters.Switches,
                    },
                    CommandHandler = handler
                });
            }
        }
示例#4
0
        private static IEnumerable <Match> MatchCommands(CommandParameters parameters, int argCount, CommandHandlerDescriptor descriptor, ICommandHandler handler)
        {
            foreach (var commandDescriptor in descriptor.Commands)
            {
                foreach (var name in commandDescriptor.Names)
                {
                    var names      = name.Split(' ');
                    var namesCount = names.Count();
                    // We check here number of arguments a command can recieve against
                    // arguments provided for the command to identify the correct command
                    // and avoid matching multiple commands.
                    if (name == string.Join(" ", parameters.Arguments.Take(namesCount)) && commandDescriptor.MethodInfo.GetParameters().Length == argCount - namesCount)
                    {
                        names = parameters.Arguments.ToArray();
                    }

                    if (parameters.Arguments.Take(argCount).SequenceEqual(names, StringComparer.OrdinalIgnoreCase))
                    {
                        yield return(new Match
                        {
                            Context = new CommandContext
                            {
                                Arguments = parameters.Arguments.Skip(name.Split(' ').Count()),
                                Command = string.Join(" ", names),
                                CommandDescriptor = commandDescriptor,
                                Input = parameters.Input,
                                Output = parameters.Output,
                                Switches = parameters.Switches,
                            },
                            CommandHandler = handler
                        });
                    }
                }
            }
        }