Exemple #1
0
        public static void HandleQuery(string query)
        {
            string[] splittedQuery = query.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            if (splittedQuery.Length == 0)
            {
                return;
            }
            string command = splittedQuery[0].ToLower();

            Command.Command deleg = CommandRegistry.GetCommandByAlias(command);
            if (deleg != null)
            {
#if !DEBUG_COMMANDS
                try
                {
#endif
                deleg.Delegate(query, splittedQuery.Skip(1).ToArray());
#if !DEBUG_COMMANDS
            }
            catch (Exception e)
            {
                CLIOutput.WriteLine("Error - {0}: {1}", ConsoleColor.DarkRed, e.GetType().Name, e.Message);
            }
#endif
            }
            else
            {
                CLIOutput.Write("No such command!", ConsoleColor.DarkRed);

                int    dist = int.MaxValue;
                string min  = null;

                foreach (string alias in CommandRegistry.EnumerateAliases())
                {
                    int dd = StringUtils.EditDistance(command, alias);
                    if (dd < dist)
                    {
                        dist = dd;
                        min  = alias;
                    }
                }

                if (dist <= 3 && min != null)
                {
                    CLIOutput.WriteLine(" Did you mean '{0}'?", ConsoleColor.DarkRed, min);
                }
                else
                {
                    CLIOutput.WriteLine();
                }
            }
        }
Exemple #2
0
 private static void CreateHandler()
 {
     handler = ReadLine.CreateHandler();
     CLIOutput.Write("> ", ConsoleColor.Green);
 }