Class CLI
java.lang.Object
org.jpos.q2.CLI
- All Implemented Interfaces:
Runnable
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCLI(Q2 q2, InputStream in, OutputStream rawout, String line, boolean keepRunning, boolean interactive) Creates a full CLI with explicit I/O streams.Creates a simple CLI with a single command and no streams. -
Method Summary
Modifier and TypeMethodDescriptionprotected org.jline.terminal.TerminalbuildTerminal(InputStream in, OutputStream out) Builds a JLine3 Terminal for this session.static voidexec(InputStream in, OutputStream out, String command) Executes a CLI command with the given I/O streams.static StringExecutes a CLI command and captures its output as a string.protected String[]Returns command prefixes registered for tab-completion.getQ2()Returns the Q2 instance this CLI is attached to.org.jline.reader.LineReaderReturns the JLine3 LineReader for this session.protected voidCalled on normal exit; subclasses may override.booleanReturns true if this CLI session is interactive.protected voidCalled when the CLI is starting; subclasses may override.protected voidCalled when the CLI is stopping; subclasses may override.voidrun()protected booleanrunning()Returns true if this CLI is still running.voidstart()Starts the CLI session.voidstop()Stops the CLI session.
-
Field Details
-
ctx
The context for this CLI session.
-
-
Constructor Details
-
CLI
Creates a simple CLI with a single command and no streams.- Parameters:
q2- the Q2 instanceline- the initial command linekeepRunning- true to keep running after the first command- Throws:
IOException- on I/O failure
-
CLI
public CLI(Q2 q2, InputStream in, OutputStream rawout, String line, boolean keepRunning, boolean interactive) throws IOException Creates a full CLI with explicit I/O streams.- Parameters:
q2- the Q2 instancein- input streamrawout- output streamline- initial command (may be null for interactive mode)keepRunning- true to keep running after commandsinteractive- true for interactive (line-edit) mode- Throws:
IOException- on I/O failure
-
-
Method Details
-
running
-
markStopped
Called when the CLI is stopping; subclasses may override. -
markStarted
Called when the CLI is starting; subclasses may override. -
getCompletionPrefixes
Returns command prefixes registered for tab-completion.- Returns:
- array of command prefixes
-
handleExit
Called on normal exit; subclasses may override. -
start
-
stop
Stops the CLI session. -
run
-
getQ2
-
isInteractive
Returns true if this CLI session is interactive.- Returns:
- true if interactive
-
getReader
Returns the JLine3 LineReader for this session.- Returns:
- the LineReader
-
exec
Executes a CLI command with the given I/O streams.- Parameters:
in- input streamout- output streamcommand- command to execute- Throws:
Exception- on execution failure
-
exec
-
buildTerminal
protected org.jline.terminal.Terminal buildTerminal(InputStream in, OutputStream out) throws IOException Builds a JLine3 Terminal for this session.- Parameters:
in- input streamout- output stream- Returns:
- the Terminal
- Throws:
IOException- on I/O failure
-