public static bool AttemptFillCommand(Game game, string[] input, Command command)
        {
            command.CallName = input[0];

            var commandInput = new List <string>();

            for (var i = 1; i < input.Length; i++)
            {
                var part = input[i];

                if (command.Tags.Any(tag => tag.NameText == part))
                {
                    var tag = command.Tags.FirstOrDefault(tag => tag.NameText == part);
                    if (command.UsedTags.Contains(tag))
                    {
                        WriteError(Text("Tag ") + tag + Text(" cannot be used more than once!"));
                        return(false);
                    }

                    command.UsedTags.Add(tag);
                    var tagInput = new List <string>();

                    i++;
                    while (i < input.Length)
                    {
                        part = input[i];

                        if (command.Tags.Any(tag => tag.NameText == part))
                        {
                            i--;
                            break;
                        }

                        tagInput.Add(part);
                        i++;
                    }

                    var success = AttemptFill(tagInput.ToArray(), tag, tag);
                    if (!success)
                    {
                        return(false);
                    }
                }
                else
                {
                    commandInput.Add(part);
                }
            }

            return(AttemptFill(commandInput.ToArray(), command, command));
        }
        public static void ProcessArguments(Game game, string[] input, List <Command> commands)
        {
            var commandName = input[0];
            var matches     = new List <Command>();

            foreach (var command in commands)
            {
                if (command.IsExactMatch(commandName))
                {
                    AttemptCommandExecution(game, input, command);
                    return;
                }

                if (command.IsMatch(commandName))
                {
                    matches.Add(command);
                }
            }

            if (matches.Count == 1)
            {
                // ONE MATCH
                AttemptCommandExecution(game, input, matches[0]);
            }
            else if (matches.Count == 0)
            {
                // NO MATCHES
                WriteError(Text("No commands starting with ") +
                           Text(commandName).Apply(Quote(), SetForeground(ColorStandards.Input)) + Text(" found."));
                var similarCommands = GetSimilarCommands(commandName);
                if (similarCommands.Count > 0)
                {
                    WriteLine("Did you mean:");
                    game.AddElement(ListElement <Command> .CreateListElement(similarCommands));
                }
            }
            else
            {
                WriteLine(Text("Commands starting with ") +
                          Text(commandName).Apply(Quote(), SetForeground(ColorStandards.Input)) + Text(":"));
                game.AddElement(ListElement <Command> .CreateListElement(matches));
            }
        }
        public static void AttemptCommandExecution(Game game, string[] input, Command command)
        {
            if (AttemptFillCommand(game, input, command))
            {
                try
                {
                    command.Action(game, command);
                }
                catch (GameException g)
                {
                    WriteError(g.Explanation);
                    g.Callback?.Invoke(game);
                }
                catch (Exception e)
                {
                    WriteError(Text(e.Message));
                    WriteError(Text(e.StackTrace));
                }
            }

            CleanUp(command);
        }