Package tigase.util.ui.console

## Class ParameterParser

- java.lang.Object
- - tigase.util.ui.console.ParameterParser

-     public class ParameterParser
      extends java.lang.Object

  General purpose command-line parser accepting (if defined) both single-letter (and space separated value) and full names (and equal-sign separated value). It also supports default values and generation of help based on configured options.

- - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `ParameterParser()` | Constructs new `ParameterParser` without any options and without interactive mode
    `ParameterParser​(boolean interactiveMode)` | Constructs new `ParameterParser` without any options and allowing enabling interactive mode
    `ParameterParser​(java.util.List<CommandlineParameter> options, boolean interactiveMode)` | Constructs new `ParameterParser` with initial options and allowing enabling interactive mode

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `addOption​(CommandlineParameter option)` | Adds `CommandlineParameter` to list of available parameters
    `void` | `addOptions​(java.util.List<CommandlineParameter> options)` | Add collection of `CommandlineParameter` to available options.
    `java.lang.String` | `getHelp()` | Generates help output with default instruction.
    `java.lang.String` | `getHelp​(java.lang.String executionCommand)` |
    `java.util.Optional<CommandlineParameter>` | `getOptionByLetter​(java.lang.String letter)` | Returns `CommandlineParameter` that matches passed parameter
    `java.util.Optional<CommandlineParameter>` | `getOptionByName​(java.lang.String commandName)` | Returns `CommandlineParameter` that matches passed parameter
    `java.util.List<CommandlineParameter>` | `getOptions()` | Retrieves List with all defined `CommandlineParameter` options
    `java.util.List<CommandlineParameter>` | `getOptions​(java.util.function.Predicate<? super CommandlineParameter> predicate)` | Retrieves List with all defined `CommandlineParameter` options that matches passed Predicate
    `java.util.List<java.lang.String>` | `getOptionsNames​(java.util.function.Predicate<? super CommandlineParameter> predicate)` | Retrieves List with all defined `CommandlineParameter` options names that matches passed Predicate
    `java.util.Optional<Task>` | `getTask()` |
    `boolean` | `isInteractiveMode()` |
    `static void` | `main​(java.lang.String[] args)` |
    `java.util.Properties` | `parseArgs​(java.lang.String[] args)` | Main parsing method which takes as an input array of parameters and returns a Properties object with parsed parameter/values.
    `void` | `removeOption​(CommandlineParameter option)` | Removes given option from list of supported options.
    `void` | `removeOptionByLetter​(java.lang.String singleLetter)` | Removes given option from list of supported options by it's single letter
    `void` | `removeOptionByName​(java.lang.String name)` | Removes given option from list of supported options by it's full name
    `void` | `setTasks​(Task[] supportedTasks)` |

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ParameterParser

          public ParameterParser()

      Constructs new `ParameterParser` without any options and without interactive mode

    - #### ParameterParser

          public ParameterParser​(boolean interactiveMode)

      Constructs new `ParameterParser` without any options and allowing enabling interactive mode
      Parameters:
        `interactiveMode` - indicates whether interactive mode should be enabled (include it in the options and handle accordingly)

    - #### ParameterParser

          public ParameterParser​(java.util.List<CommandlineParameter> options,
                                 boolean interactiveMode)

      Constructs new `ParameterParser` with initial options and allowing enabling interactive mode
      Parameters:
        `options` - initial list of available options
        `interactiveMode` - indicates whether interactive mode should be enabled (include it in the options and handle accordingly)

  - ### Method Detail

    - #### main

          public static void main​(java.lang.String[] args)

    - #### addOption

          public void addOption​(CommandlineParameter option)
                         throws java.lang.IllegalArgumentException

      Adds `CommandlineParameter` to list of available parameters
      Parameters:
        `option` - a `CommandlineParameter` that should be added
      Throws:
        `java.lang.IllegalArgumentException` - is thrown when the same option (either same name or same short-letter) exists in the defined list.

    - #### addOptions

          public void addOptions​(java.util.List<CommandlineParameter> options)

      Add collection of `CommandlineParameter` to available options. Calls internally `addOption(tigase.util.ui.console.CommandlineParameter)`
      Parameters:
        `options` - collection of `CommandlineParameter` to be added.

    - #### getHelp

          public java.lang.String getHelp()

      Generates help output with default instruction.
      Returns:
        String with default instruction.

    - #### getHelp

          public java.lang.String getHelp​(java.lang.String executionCommand)

      Parameters:
        `executionCommand` - an example of the execution command, for example `$ java -cp \"jars/*.jar\" tigase.util.DBSchemaLoader [options]`
      Returns:
        string representing all the available options and their description

    - #### getOptionByLetter

          public java.util.Optional<CommandlineParameter> getOptionByLetter​(java.lang.String letter)

      Returns `CommandlineParameter` that matches passed parameter
      Parameters:
        `letter` - single-letter identification of the `CommandlineParameter`
      Returns:
        an Optional `CommandlineParameter` that matches passed letter.

    - #### getOptionByName

          public java.util.Optional<CommandlineParameter> getOptionByName​(java.lang.String commandName)

      Returns `CommandlineParameter` that matches passed parameter
      Parameters:
        `commandName` - full-name identification of the `CommandlineParameter`
      Returns:
        an Optional `CommandlineParameter` that matches passed name.

    - #### getOptions

          public java.util.List<CommandlineParameter> getOptions()

      Retrieves List with all defined `CommandlineParameter` options
      Returns:
        List with all defined `CommandlineParameter` options

    - #### getOptions

          public java.util.List<CommandlineParameter> getOptions​(java.util.function.Predicate<? super CommandlineParameter> predicate)

      Retrieves List with all defined `CommandlineParameter` options that matches passed Predicate
      Parameters:
        `predicate` - by which list should be filtered
      Returns:
        List of `CommandlineParameter` filtered to matching options.

    - #### getOptionsNames

          public java.util.List<java.lang.String> getOptionsNames​(java.util.function.Predicate<? super CommandlineParameter> predicate)

      Retrieves List with all defined `CommandlineParameter` options names that matches passed Predicate
      Parameters:
        `predicate` - by which list should be filtered
      Returns:
        List of `CommandlineParameter` names filtered to matching options.

    - #### getTask

          public java.util.Optional<Task> getTask()

    - #### isInteractiveMode

          public boolean isInteractiveMode()

    - #### parseArgs

          public java.util.Properties parseArgs​(java.lang.String[] args)

      Main parsing method which takes as an input array of parameters and returns a Properties object with parsed parameter/values. It supports both single letter format (`-X value` as well as full name (`--name=value`). In case no value for defined option was passed but it's defined as required and contains default value it will be included in the resulting Properties. If interactive mode is enabled, there will be a prompt for all missing options (defined but not included in passed parameter)
      Parameters:
        `args` - an input array of parameters and defined values.
      Returns:
        Properties with parameter/value pairs matching defined options.

    - #### removeOption

          public void removeOption​(CommandlineParameter option)

      Removes given option from list of supported options.
      Parameters:
        `option` - `commandlineParameter` option to be removed

    - #### removeOptionByLetter

          public void removeOptionByLetter​(java.lang.String singleLetter)

      Removes given option from list of supported options by it's single letter
      Parameters:
        `singleLetter` - identification of the option

    - #### removeOptionByName

          public void removeOptionByName​(java.lang.String name)

      Removes given option from list of supported options by it's full name
      Parameters:
        `name` - full name identification of the option

    - #### setTasks

          public void setTasks​(Task[] supportedTasks)