Class SimpleCommandLineParser

java.lang.Object
org.dellroad.jct.core.simple.SimpleCommandLineParser
All Implemented Interfaces:
CommandLineParser

public class SimpleCommandLineParser extends Object implements CommandLineParser
A simple command line parser:
  • Command name and parameters are separated by whitespace
  • Java-style doubly-quoted string literals are supported, and may span multiple lines
  • Backslash escapes are supported for (in particular) double quote and backslash characters
  • Backslash escapes are supported for end of line continuations to the next line
  • Constructor Details

    • SimpleCommandLineParser

      public SimpleCommandLineParser()
  • Method Details

    • parseCommandLine

      public List<String> parseCommandLine(String line) throws CommandLineParser.SyntaxException
      Description copied from interface: CommandLineParser
      Parse the given command line into a command name and parameters.

      If the line contains a syntax error, then a CommandLineParser.SyntaxException should be thrown.

      If the line does not contain even a command name, for example is pure whitespace, then an empty list should be returned.

      If the line contains ends with an incomplete parse (e.g., with a backslash continuation character), then null should be returned. In this case the caller should read another line of input, append it to the original (after adding a line terminator), and then invoke this method again.

      Specified by:
      parseCommandLine in interface CommandLineParser
      Parameters:
      line - command line
      Returns:
      parsed command line
      Throws:
      CommandLineParser.SyntaxException - if line contains a syntax error