Package readycli

Class CommandContext

java.lang.Object
readycli.CommandContext

public final class CommandContext
extends java.lang.Object
Collects all the information that results from command parsing, i.e. actual values of the required arguments and options, and the input and the output streams used to interact with the user. The instances of this class are created by the Command class and submitted to a CommandExecutor when the command is parsed.
Author:
Salvatore Giampa'
  • Field Summary

    Fields 
    Modifier and Type Field Description
    java.util.Map<java.lang.String,​java.lang.String> arguments
    Contains all values of all arguments.
    java.io.InputStream in
    The input stream used to interact with the user.
    java.util.Map<java.lang.String,​OptionValues> options
    Contains all values of all options.
    java.io.PrintStream out
    The output stream used to interact with the user.
  • Method Summary

    Modifier and Type Method Description
    java.lang.String getArgument​(java.lang.String name)
    Gets the value of an argument.
    OptionValues getOption​(java.lang.String name)
    Gets the parameter values of an option.
    Invoking this method, has the same effect of the following code:
    context.options.get(name);

    Methods inherited from class java.lang.Object

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

    • arguments

      public final java.util.Map<java.lang.String,​java.lang.String> arguments
      Contains all values of all arguments. This is an unmodifiable map.
      • Key: argument name;
      • Value: argument value;
    • options

      public final java.util.Map<java.lang.String,​OptionValues> options
      Contains all values of all options. This is an unmodifiable map.
      • Key: option name;
      • Value: option values;
    • out

      public final java.io.PrintStream out
      The output stream used to interact with the user.
    • in

      public final java.io.InputStream in
      The input stream used to interact with the user.
  • Method Details

    • getArgument

      public java.lang.String getArgument​(java.lang.String name)
      Gets the value of an argument.
      Invoking this method, has the same effect of the following code:
      context.arguments.get(name);
      Parameters:
      name - the name of the argument
      Returns:
      the string value of the argument
    • getOption

      public OptionValues getOption​(java.lang.String name)
      Gets the parameter values of an option.
      Invoking this method, has the same effect of the following code:
      context.options.get(name);
      Parameters:
      name - the name of the option
      Returns:
      an OptionValues object containing the values of the option