Class AbstractCommandLineParser

java.lang.Object
megamek.common.commandLine.AbstractCommandLineParser
Direct Known Subclasses:
ClientServerCommandLineParser, MegaMekCommandLineParser

public abstract class AbstractCommandLineParser extends Object
Very simple skeleton for the command line parser. Provides basic scanner primitives and token types. Descendants should implement at least start function
  • Field Details

    • OPTION_PREFIX

      protected String OPTION_PREFIX
      Prefix of the option. Subclasses may overwrite.
    • TOK_EOF

      protected static final int TOK_EOF
      End of input token
      See Also:
    • TOK_OPTION

      protected static final int TOK_OPTION
      Option token
      See Also:
    • TOK_LITERAL

      protected static final int TOK_LITERAL
      Literal (any string that does not start with defice (sp?) actually)
      See Also:
  • Constructor Details

    • AbstractCommandLineParser

      public AbstractCommandLineParser(String... args)
      Constructs new parser
      Parameters:
      args - array of arguments to parse
  • Method Details

    • parse

      public void parse() throws AbstractCommandLineParser.ParseException
      Main entry point of the parser
      Throws:
      AbstractCommandLineParser.ParseException - if it fails to parse
    • getArgValue

      protected String getArgValue()
      Returns:
      current argument
    • getTokenType

      protected int getTokenType()
      Returns:
      current token
    • setToken

      protected void setToken(int token)
      Parameters:
      token - to set the current token to
    • getTokenValue

      protected String getTokenValue()
      Returns:
      String value of the current token
    • setTokenValue

      protected void setTokenValue(String tokenValue)
      Parameters:
      tokenValue - to set the current token to
    • getPosition

      protected int getPosition()
      Returns:
      String value of the current token
    • start

      protected abstract void start() throws AbstractCommandLineParser.ParseException
      Real entry point of parser
      Throws:
      AbstractCommandLineParser.ParseException - if the parser fails
    • help

      public abstract String help()
    • hasNext

      protected boolean hasNext()
    • nextToken

      protected void nextToken()
      Reads the next available token.
    • nextArg

      protected void nextArg()