Exemple #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);
     }
 }
Exemple #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();
        }
Exemple #3
0
 private static void Exec(string fileName)
 {
     try
     {
         CommandConsole.Current.Shell.ExecuteLsf(fileName);
     }
     catch (FileNotFoundException)
     {
         LConsole.WriteLine("File not found", ConsoleColor.Red);
     }
 }
Exemple #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());
            }
        }
Exemple #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();
            }
        }
Exemple #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();
        }
Exemple #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();
            }
        }
Exemple #8
0
 private static void Echo(object obj)
 {
     LConsole.WriteLine(obj?.ToString() ?? "null");
 }