Package org.openhab.core.io.console
Class ConsoleInterpreter
java.lang.Object
org.openhab.core.io.console.ConsoleInterpreter
This class provides generic methods for handling console input (i.e. pure strings).
- Author:
- Kai Kreuzer - Initial contribution, Markus Rathgeb - Change interface
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidexecute(Console console, ConsoleCommandExtension extension, String[] args) Executes a console command extension with the given arguments.static StringgetHelp(String base, String separator, Collection<ConsoleCommandExtension> extensions) Generates a formatted help message listing all available console commands.static StringgetUsage(Collection<ConsoleCommandExtension> consoleCommandExtensions) Returns a newline-separated list of usage texts for all available commands.getUsages(Collection<ConsoleCommandExtension> consoleCommandExtensions) Returns a list of usage texts for all available commands.static voidprintHelp(Console console, String base, String separator, Collection<ConsoleCommandExtension> extensions) Prints the formatted help message to the console.
-
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 tobase- 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
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 outputextension- the console command extension to executeargs- the arguments to pass to the command
-
getUsage
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
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
-