Пример #1
0
 public CommandMap(CommandMap parent, string name, string fullName)
     : this()
 {
     _parent   = parent;
     _name     = name;
     _fullName = fullName;
 }
Пример #2
0
        private void AddCommand(int index, string[] parts, Command command, bool isAlias)
        {
            if (!command.IsHidden)
            {
                _isVisible = true;
            }

            if (index != parts.Length)
            {
                CommandMap nextGroup;
                string     name     = parts[index].ToLowerInvariant();
                string     fullName = string.Join(" ", parts, 0, index + 1);
                if (!_items.TryGetValue(name, out nextGroup))
                {
                    nextGroup = new CommandMap(this, name, fullName);
                    _items.Add(name, nextGroup);
                    _hasSubGroups = true;
                }
                nextGroup.AddCommand(index + 1, parts, command, isAlias);
            }
            else
            {
                _commands.Add(command);
                if (!isAlias)
                {
                    _hasNonAliases = true;
                }
            }
        }
Пример #3
0
        public CommandService(CommandServiceConfig config)
        {
            Config = config;

            _allCommands = new List <Command>();
            _map         = new CommandMap();
            _categories  = new Dictionary <string, CommandMap>();
            Root         = new CommandGroupBuilder(this);
        }
Пример #4
0
        public static bool ParseCommand(string input, CommandMap map, out IEnumerable <Command> commands, out int endPos)
        {
            int  startPosition = 0;
            int  endPosition   = 0;
            int  inputLength   = input.Length;
            bool isEscaped     = false;

            commands = null;
            endPos   = 0;

            if (input == "")
            {
                return(false);
            }

            while (endPosition < inputLength)
            {
                char currentChar = input[endPosition++];
                if (isEscaped)
                {
                    isEscaped = false;
                }
                else if (currentChar == '\\')
                {
                    isEscaped = true;
                }

                bool isWhitespace = IsWhiteSpace(currentChar);
                if ((!isEscaped && isWhitespace) || endPosition >= inputLength)
                {
                    int    length = (isWhitespace ? endPosition - 1 : endPosition) - startPosition;
                    string temp   = input.Substring(startPosition, length);
                    if (temp == "")
                    {
                        startPosition = endPosition;
                    }
                    else
                    {
                        var newMap = map.GetItem(temp);
                        if (newMap != null)
                        {
                            map    = newMap;
                            endPos = endPosition;
                        }
                        else
                        {
                            break;
                        }
                        startPosition = endPosition;
                    }
                }
            }
            commands = map.GetCommands();             //Work our way backwards to find a command that matches our input
            return(commands != null);
        }
Пример #5
0
        internal void AddCommand(Command command)
        {
            _allCommands.Add(command);

            //Get category
            string categoryName = command.Category ?? "";

            if (!_categories.TryGetValue(categoryName, out CommandMap category))
            {
                category = new CommandMap();
                _categories.Add(categoryName, category);
            }

            //Add main command
            category.AddCommand(command.Text, command, false);
            _map.AddCommand(command.Text, command, false);

            //Add aliases
            foreach (var alias in command.Aliases)
            {
                category.AddCommand(alias, command, true);
                _map.AddCommand(alias, command, true);
            }
        }