Package io.jawk

Class Cli

java.lang.Object
io.jawk.Cli

public final class Cli extends Object
Command-line interface for Jawk.
  • Constructor Details

    • Cli

      public Cli()
      Creates a CLI instance wired to the standard input and output streams.
    • Cli

      public Cli(InputStream in, PrintStream out, PrintStream err)
      Creates a CLI instance using the supplied streams.
      Parameters:
      in - stream from which program input is read
      out - stream where program output is written
      err - stream where error messages could be written
  • Method Details

    • getSettings

      public AwkSettings getSettings()
      Returns the mutable AwkSettings configured from the command line.
      Returns:
      the settings object populated during argument parsing
    • isSandbox

      public boolean isSandbox()
      Indicates whether sandbox mode was requested on the command line.
      Returns:
      true when sandbox mode is enabled
    • isDisableOptimize

      public boolean isDisableOptimize()
      Indicates whether tuple optimization was explicitly disabled.
      Returns:
      true when optimization should be skipped
    • isProfiling

      public boolean isProfiling()
      Indicates whether runtime profiling was requested.
      Returns:
      true when profiling should be enabled
    • getScriptSources

      public List<ScriptSource> getScriptSources()
      Returns the list of script sources specified on the command line.
      Returns:
      defensive copy of the script sources list
    • getPrecompiledProgram

      public AwkProgram getPrecompiledProgram()
      Returns the precompiled program loaded via the -L option, if any.
      Returns:
      the program or null if none were loaded
    • parse

      public void parse(String[] args)
      Parses the supplied command-line arguments and configures this instance accordingly.
      Parameters:
      args - command-line arguments
    • run

      public void run() throws Exception
      Executes the CLI based on the previously parsed arguments.
      Throws:
      Exception - if compilation or execution fails
    • parseCommandLineArguments

      public static Cli parseCommandLineArguments(String[] args)
      Parses command-line arguments into a new Cli instance without executing it.
      Parameters:
      args - command-line arguments
      Returns:
      configured CLI instance
    • create

      public static Cli create(String[] args, InputStream is, PrintStream os, PrintStream es) throws Exception
      Convenience factory that parses arguments, executes the CLI, and returns the configured instance.
      Parameters:
      args - command-line arguments
      is - input stream for program input
      os - output stream for program output
      es - error stream for diagnostic messages
      Returns:
      configured and executed CLI instance
      Throws:
      Exception - if execution fails
    • main

      public static void main(String[] args)
      Entry point for the command-line interface.

      This method carries process semantics: because it is what the jawk launch of the JVM runs, it declares that the standard input the CLI reads is the standard input of the process, and the children of system() and of command pipes may inherit it, as POSIX requires. No Java-side check can distinguish the launcher-installed System.in from a replacement installed with System.setIn, so that declaration is part of this method's contract: code that replaces System.in must not call main programmatically — embedders and tests go through create(String[], InputStream, PrintStream, PrintStream), the constructors, or the Awk API, where spawned children always get a closed standard input instead.

      Parameters:
      args - command-line arguments