Class CLI

java.lang.Object
org.jpos.q2.CLI
All Implemented Interfaces:
Runnable

public class CLI extends Object implements Runnable
Interactive command-line interface for a running Q2 instance.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected CLIContext
    The context for this CLI session.
  • Constructor Summary

    Constructors
    Constructor
    Description
    CLI(Q2 q2, InputStream in, OutputStream rawout, String line, boolean keepRunning, boolean interactive)
    Creates a full CLI with explicit I/O streams.
    CLI(Q2 q2, String line, boolean keepRunning)
    Creates a simple CLI with a single command and no streams.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected org.jline.terminal.Terminal
    Builds a JLine3 Terminal for this session.
    static void
    exec(InputStream in, OutputStream out, String command)
    Executes a CLI command with the given I/O streams.
    static String
    exec(String command)
    Executes a CLI command and captures its output as a string.
    protected String[]
    Returns command prefixes registered for tab-completion.
    Returns the Q2 instance this CLI is attached to.
    org.jline.reader.LineReader
    Returns the JLine3 LineReader for this session.
    protected void
    Called on normal exit; subclasses may override.
    boolean
    Returns true if this CLI session is interactive.
    protected void
    Called when the CLI is starting; subclasses may override.
    protected void
    Called when the CLI is stopping; subclasses may override.
    void
    run()
     
    protected boolean
    Returns true if this CLI is still running.
    void
    Starts the CLI session.
    void
    Stops the CLI session.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • ctx

      protected CLIContext ctx
      The context for this CLI session.
  • Constructor Details

    • CLI

      public CLI(Q2 q2, String line, boolean keepRunning) throws IOException
      Creates a simple CLI with a single command and no streams.
      Parameters:
      q2 - the Q2 instance
      line - the initial command line
      keepRunning - 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 instance
      in - input stream
      rawout - output stream
      line - initial command (may be null for interactive mode)
      keepRunning - true to keep running after commands
      interactive - true for interactive (line-edit) mode
      Throws:
      IOException - on I/O failure
  • Method Details

    • running

      protected boolean running()
      Returns true if this CLI is still running.
      Returns:
      true if running
    • markStopped

      protected void markStopped()
      Called when the CLI is stopping; subclasses may override.
    • markStarted

      protected void markStarted()
      Called when the CLI is starting; subclasses may override.
    • getCompletionPrefixes

      Returns command prefixes registered for tab-completion.
      Returns:
      array of command prefixes
    • handleExit

      protected void handleExit()
      Called on normal exit; subclasses may override.
    • start

      public void start() throws Exception
      Starts the CLI session.
      Throws:
      Exception - on startup failure
    • stop

      public void stop()
      Stops the CLI session.
    • run

      public void run()
      Specified by:
      run in interface Runnable
    • getQ2

      public Q2 getQ2()
      Returns the Q2 instance this CLI is attached to.
      Returns:
      the Q2 instance
    • isInteractive

      public boolean isInteractive()
      Returns true if this CLI session is interactive.
      Returns:
      true if interactive
    • getReader

      public org.jline.reader.LineReader getReader()
      Returns the JLine3 LineReader for this session.
      Returns:
      the LineReader
    • exec

      public static void exec(InputStream in, OutputStream out, String command) throws Exception
      Executes a CLI command with the given I/O streams.
      Parameters:
      in - input stream
      out - output stream
      command - command to execute
      Throws:
      Exception - on execution failure
    • exec

      public static String exec(String command) throws Exception
      Executes a CLI command and captures its output as a string.
      Parameters:
      command - command string to execute
      Returns:
      captured output
      Throws:
      Exception - on execution failure
    • buildTerminal

      protected org.jline.terminal.Terminal buildTerminal(InputStream in, OutputStream out) throws IOException
      Builds a JLine3 Terminal for this session.
      Parameters:
      in - input stream
      out - output stream
      Returns:
      the Terminal
      Throws:
      IOException - on I/O failure