Class ConsoleInterpreter

java.lang.Object
org.openhab.core.io.console.ConsoleInterpreter

@NonNullByDefault public class ConsoleInterpreter extends Object
This class provides generic methods for handling console input (i.e. pure strings).
Author:
Kai Kreuzer - Initial contribution, Markus Rathgeb - Change interface
  • Constructor Details

    • ConsoleInterpreter

      public ConsoleInterpreter()
  • Method Details

    • getHelp

      public static String getHelp(String base, String separator, Collection<ConsoleCommandExtension> extensions)
      Generates a formatted help message listing all available console commands. This method creates a comprehensive help text that includes all command extensions with their usage information, formatted with the specified base command and separator.
      Parameters:
      base - the base command string (e.g., "openhab")
      separator - the separator between base and command (e.g., ":")
      extensions - the collection of console command extensions to include in the help
      Returns:
      a formatted string containing all command usages
    • printHelp

      public static void printHelp(Console console, String base, String separator, Collection<ConsoleCommandExtension> extensions)
      Prints the formatted help message to the console. This is a convenience method that generates and prints the help text for all available console commands.
      Parameters:
      console - the console to print the help message to
      base - the base command string (e.g., "openhab")
      separator - the separator between base and command (e.g., ":")
      extensions - the collection of console command extensions to include in the help
    • execute

      public static void execute(Console console, ConsoleCommandExtension extension, String[] args)
      Executes a console command extension with the given arguments. This method wraps the execution with error handling, logging any exceptions that occur and providing user-friendly error messages to the console.
      Parameters:
      console - the console for command output
      extension - the console command extension to execute
      args - the arguments to pass to the command
    • getUsage

      public static String getUsage(Collection<ConsoleCommandExtension> consoleCommandExtensions)
      Returns a newline-separated list of usage texts for all available commands. Each usage text is on its own line, providing a complete list of all command usages from the given console command extensions.
      Parameters:
      consoleCommandExtensions - the collection of console command extensions
      Returns:
      a newline-separated string containing all command usage texts
    • getUsages

      public static List<String> getUsages(Collection<ConsoleCommandExtension> consoleCommandExtensions)
      Returns a list of usage texts for all available commands. This method collects all usage strings from the given console command extensions and returns them as a list.
      Parameters:
      consoleCommandExtensions - the collection of console command extensions
      Returns:
      a list containing all command usage texts