Module FiCLI
Package fibrous.fi

Class FiCLI

java.lang.Object
fibrous.fi.FiCLI

public class FiCLI extends Object
Parses text input, and executes commands accordingly. Add FiCommand objects via the addCommand() method. Will list the available commands and their configured descriptions when the listCommandsString is input. The listCommandsString is configurable via an appropriate constructor. Output from this class can be directed to anything by creating an object that implements FiOutputStream and passing it through the appropriate constructor.
Author:
noahm
  • Constructor Details

    • FiCLI

      public FiCLI(FiInputStream is, FiOutputStream os, String listCommandsString)
      Creates a new InputParser with a configurable FiOutputStream and FiInputStream.
      Parameters:
      os - The FiOutputStream object that this parser will use to directly output data.
      listCommandsString - What input string should show all of the commands that have been configured.
    • FiCLI

      public FiCLI(String listCommandsString)
      Creates a new InputParser using the default FiConsoleIO.
      Parameters:
      listCommandsString - What input string should show all of the commands that have been configured.
    • FiCLI

      public FiCLI()
      Creates a new InputParser using the default FiConsoleIO, and a default listCommndsString of '?'.
  • Method Details

    • addCommand

      public void addCommand(FiCommand command)
      Adds a command that will be executed when input matches it's defined syntax.
      Parameters:
      command -
    • setCommands

      public void setCommands(ArrayList<FiCommand> commands)
      Sets the list of commands through an ArrayList containing FiCommand objects.
      Parameters:
      commands -
    • getCommands

      public ArrayList<FiCommand> getCommands()
      Returns an ArrayList containing all of the currently configured commands.
      Returns:
    • clearCommands

      public void clearCommands()
      Removes all commands.
    • setExitString

      public void setExitString(String s)
      Determines what String will return FiState.EXIT when doCommand() is called. This may be synonymous with the FiState.BACK state in certain contexts. In general, this state is used to determine if the application should exit. Using this method also automatically allows FiState.EXIT to be returned.
      Parameters:
      s -
    • setBackString

      public void setBackString(String s)
      Determines what String will return FiState.BACK when doCommand() is called. This may be synonymous with the FiState.EXIT state in certain contexts and configurations. In general, this state is used to determine if this parser should close, and not the application itself. It is useful in menu systems where nested parsers are implemented, and you still want to allow exiting from the application, regardless of where in the CLI the user is. Using this method also automatically allows FiState.BACK to be returned.
      Parameters:
      s -
    • allowAdditionalStates

      public void allowAdditionalStates(boolean exit, boolean back)
      Determines if the processCommand method can return with FiState.EXIT or BACK.
      Parameters:
      exit -
      back -
    • setExitDescription

      public void setExitDescription(String desc)
      Sets the description that the exit command will show (when FiState.EXIT is allowed to be returned.)
      Parameters:
      desc -
    • setBackDescription

      public void setBackDescription(String desc)
      Sets the description that the back command will show (when FiState.BACK is allowed to be returned.)
      Parameters:
      desc -
    • setCaret

      public void setCaret(String c)
      Sets the caret.
      Parameters:
      c -
    • getCaret

      public String getCaret()
      Returns the currently configured caret.
      Returns:
    • setInput

      public void setInput(FiInputStream fis)
      Sets the input system.
      Parameters:
      fis -
    • setOutput

      public void setOutput(FiOutputStream fos)
      Sets the output system.
      Parameters:
      fos -
    • processCommand

      public FiState processCommand()
      Outputs the caret, indicating that input is requested, and then waits for input and reacts accordingly. Checks a string that is passed and attempts to match it against a stored command or other special command. If the string is a valid command, it executes the command, and returns true. If not, nothing happens and it returns false, which allows you to create your own error handling.
      Returns:
    • numOfCommands

      public int numOfCommands()
      Returns the number of currently configured commands.
      Returns: