Exemplo n.º 1
0
Arquivo: Cmd.java Projeto: Rojoss/Boxx
  /**
   * Register a command flag for this command.
   *
   * <p>A command flag represents a boolean that can be added anywhere in the command. The specified
   * name must be used by the user to specify the flag.
   *
   * <p>For example if the name is 'f' the user can specify '-f' anywhere in the command.
   *
   * <p>You don't have to prefix the name with a '-' If you do it will be removed so if you want to
   * have the user put '--f' you have to set the name as '--f'
   *
   * @param name The flag name/key used to identify the flag. This name must be used with the {@link
   *     CmdData} result to check if the flag was specified. This name is also what the user needs
   *     to use to specify the flag. (-{name}) The name '?' is reserved!
   * @return The added {@link Flag}
   * @throws IllegalArgumentException if a flag with the specified name is already registered for
   *     this command.
   */
  public Flag addFlag(String name) {
    if (name.startsWith("-")) {
      name = name.substring(1);
    }

    Flag flag = new Flag(name);
    if (getAllFlags().containsKey(name.toLowerCase())) {
      throw new IllegalArgumentException(
          "The command already has a flag with the name '-" + name + "'!");
    }

    flags.put(name.toLowerCase(), flag);
    return flag;
  }
Exemplo n.º 2
0
Arquivo: Cmd.java Projeto: Rojoss/Boxx
  /**
   * Register a command modifier for this command.
   *
   * <p>A command modifier is an optional argument that can be added anywhere in the command. The
   * specified name must be used by the user to specify the modifier.
   *
   * <p>For example if you register a modifier with the name player and the option is a {@link
   * PlayerO} The user would put player:{player} anywhere in the command to set the modifer value.
   *
   * @param name The modifier name/key used to identify the argument. This name must be used with
   *     the {@link CmdData} result to get the modifier value. This name is also what the user needs
   *     to use to specify the modifier. ({name}:{value})
   * @param option The {@link SingleOption} used for parsing the modifier. This option determines
   *     the modifier value and everything else. For example if it's a {@link PlayerO} the modifier
   *     value must be a player and the result value would be a player. This option can't be a sub
   *     command option!
   * @return The added {@link Modifier}
   * @throws IllegalArgumentException if a modifier with the specified name is already registered
   *     for this command or if the modifier has a sub command option.
   */
  public Modifier addModifier(String name, SingleOption option) {
    Modifier modifier = new Modifier(name, option);

    if (option instanceof SubCmdO) {
      throw new IllegalArgumentException(
          "Modifiers can not be a sub command option! [modifier=" + name + "]");
    }

    if (getAllModifiers().containsKey(name.toLowerCase())) {
      throw new IllegalArgumentException(
          "The command already has a modifier with the name '" + name + "'!");
    }

    modifiers.put(name.toLowerCase(), modifier);
    return modifier;
  }