public virtual void Invoke(string data)
        {
            if (!MethodParser.TryParse(data, out var arguments))
            {
                // Failed to parse input. Show usage
                DeveloperConsole.LogWarning($"{MethodParser.CalculateUsage(Name)}\n" +
                                            $"Try '{typeof(HelpCommand).GetCustomAttribute<CommandAttribute>().Name} {Name}' for more information.");
                return;
            }

            Method.Invoke(Target, arguments);
        }
Exemple #2
0
        public void Invoke(string data)
        {
            var args = DeveloperConsole.SplitArgs(data);

            if (args.Length == 0)
            {
                Invoke();
            }
            else
            {
                // Find a verb whose name is the first argument
                var verb = args[0].Trim().ToLower();

                foreach (var pair in mVerbs)
                {
                    if (pair.Key.Equals(verb))
                    {
                        pair.Value.Command.Invoke(data.Substring(DeveloperConsole.SplitPositions[0]));
                        return;
                    }
                }

                // No verb with that name
                DeveloperConsole.LogWarning($"'{Name}': no such verb with name '{args[0]}' could be found.");
                if (mVerbs.Count > 0)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.AppendLine("Possible subcommands are: ");
                    var verbsAlphabetized = (from pair in mVerbs
                                             let v = pair.Value
                                                     orderby v.Name
                                                     select v);

                    foreach (var v in verbsAlphabetized)
                    {
                        sb.AppendLine($"    * {Name} {v.Name}");
                    }
                    DeveloperConsole.LogWarning(sb.ToString());
                }
            }
        }
Exemple #3
0
 private void LogWarning(object message) => DeveloperConsole.LogWarning($"{kCommandName}: {message}");
Exemple #4
0
 private static void LogWarning(string commandName, object message) => DeveloperConsole.LogWarning($"{commandName}: {message}");