예제 #1
0
 private void Frontend_LineInput(string line)
 {
     try
     {
         Shell.ExecuteLine(line);
     }
     catch (CommandNotFoundException ex)
     {
         LConsole.WriteLine(ex.Message, ConsoleColor.Red);
     }
     catch (ParameterMismatchException ex)
     {
         LConsole.WriteLine(ex.Message, ConsoleColor.Red);
         ex.Command.PrintUsage();
     }
     catch (ParameterConversionException ex)
     {
         LConsole.WriteLine(ex.Message, ConsoleColor.Red);
     }
     catch (ParserException ex)
     {
         LConsole.WriteLine("Error when parsing command: " + ex.Message, ConsoleColor.Red);
     }
     catch (Exception ex)
     {
         LConsole.WriteLine("An error occurred when executing this command:", ConsoleColor.Red);
         LConsole.WriteLine(ex.ToString(), ConsoleColor.Red);
     }
 }
예제 #2
0
        private static void Help()
        {
            int totalCommandCount = CommandConsole.Current.CommandRegistry.AllRegisteredCommands.GetCommandCount();

            if (totalCommandCount == 0)
            {
                LConsole.WriteLine("Uh oh, there aren't any registered commands");
                return;
            }


            int maxUsageLength = GetMaxCommandUsageLength(CommandConsole.Current.CommandRegistry.AllRegisteredCommands.EnumerateAllCommands());

            LineWriter writer = LConsole.BeginLine();

            writer.WriteLine($"Available commands ({totalCommandCount}):", ConsoleColor.Magenta);
            writer.WriteLine();

            foreach (string assemblyName in CommandConsole.Current.CommandRegistry.CommandsByAssembly.Keys.OrderBy(s => s))
            {
                WriteAssemblyCommands(maxUsageLength, writer, assemblyName);
                writer.WriteLine();
            }

            writer.End();
        }
예제 #3
0
 private static void Exec(string fileName)
 {
     try
     {
         CommandConsole.Current.Shell.ExecuteLsf(fileName);
     }
     catch (FileNotFoundException)
     {
         LConsole.WriteLine("File not found", ConsoleColor.Red);
     }
 }
예제 #4
0
        private static void PrintException()
        {
            var ex = CommandConsole.Current.Shell.LastException;

            if (ex == null)
            {
                LConsole.WriteLine("No exception has occurred so far!", ConsoleColor.Green);
            }
            else
            {
                LConsole.WriteLine(ex.ToString());
            }
        }
예제 #5
0
        private static void Help(string commandName)
        {
            if (!CommandConsole.Current.CommandRegistry.AllRegisteredCommands.ContainsCommand(commandName))
            {
                LConsole.WriteLine($"No registered command with name '{commandName}'", ConsoleColor.Red);
                return;
            }

            foreach (var cmd in CommandConsole.Current.CommandRegistry.AllRegisteredCommands.GetEntry(commandName).Commands)
            {
                cmd.PrintUsage();
            }
        }
예제 #6
0
        private static void HelpAss(string assemblyName)
        {
            if (!CommandConsole.Current.CommandRegistry.CommandsByAssembly.TryGetValue(assemblyName, out var commands))
            {
                LConsole.WriteLine($"No assembly with commands found by name {assemblyName}. See `help` for commands in all assemblies.");
                return;
            }


            int maxUsageLength = GetMaxCommandUsageLength(commands);

            LineWriter writer = LConsole.BeginLine();

            WriteAssemblyCommands(maxUsageLength, writer, assemblyName);
            writer.End();
        }
예제 #7
0
        private static void PrintEnvironment()
        {
            if (!CommandConsole.Current.Config.EnableVariables)
            {
                LConsole.WriteLine("Variables are disabled", ConsoleColor.Red);
                return;
            }

            foreach (var item in CommandConsole.Current.Shell.Environment.GetAll())
            {
                LConsole.BeginLine()
                .Write(item.Key, ConsoleColor.DarkGreen)
                .Write(" = ", ConsoleColor.DarkGray)
                .Write(item.Value)
                .End();
            }
        }
예제 #8
0
 private static void Echo(object obj)
 {
     LConsole.WriteLine(obj?.ToString() ?? "null");
 }