Console Parallax
A simple Java library handling console input and treating it as a CLI. It is designed to be quickly used, without any fuss and large amount of code or reading.
With the magic of annotations and without. It is up to you.
Installation
Java >= 8
Maven
Gradle
Features
Handling of console (or any other) input as a CLI
Registering commands
Quick showcase
Documentation
ConsoleParallax
class
This class is the main class of the library. Calling #start()
will start the command reader thread.
The command reader thread calls InputHandler#getNextInput()
to get the next input. The default implementation of ConsoleInputHandler
calls Scanner#nextLine()
on System.in
.
All commands are executed on ConsoleParallax
's command executor.
You may create the ConsoleParallax
instance with a (long) constructor or with its Builder
:
Default implementations (click to see):
Custom implementations
You may create your own implementations of InputHandler
, OutputHandler
and even CommandParser
. Please, see existing implementations for reference.
Pro tip: Logging
Your application may use different type of logging than just printing to the console. You can create your own implementation of OutputHandler
and override the two methods in there - #info()
and #error()
.
Help command
There's pre-implemented help command that shows you all registered commands. You can register it by calling ConsoleParallax#registerDefaultHelpCommand()
.
I also recommend using this command as a reference.
Custom commands
As seen in the quick showcase, all commands are just declared classes that implement BaseCommand
interface.
There are several methods:
Method | Description |
---|---|
| returns the name of the command, should be lowercase, without spaces |
| the method that is called when the command is executed |
| returns short description of the command, used in the help command |
| returns command's syntax, e.g., example <arg1> [arg2] |
| returns long description of the command, used in the help command |
Here you can find pre-implemented Help command as a reference
CommandInvocationContext
class
This class holds some information about the command's invocation:
Method | Description |
---|---|
| returns the instance of ConsoleParallax that called the command |
| returns the command's name that was specified in the input (calls |
| returns the arguments that were specified in the input (calls |
| returns the result of the command parsing ( |
Future plans
Annotations (
@Command
,@Argument
, etc.) with type checksAdvanced command parser (
--help
,--name="some-value"
, greedy strings, etc.)