Class ToolOptions


  • public class ToolOptions
    extends Object
    Wrapper around CommandLine to provide a more user friendly syntax, in particular based on Optionals.
    Author:
    Sylvain Leclerc
    • Constructor Detail

      • ToolOptions

        public ToolOptions​(org.apache.commons.cli.CommandLine line,
                           FileSystem fileSystem)
      • ToolOptions

        public ToolOptions​(org.apache.commons.cli.CommandLine line,
                           ToolRunningContext context)
    • Method Detail

      • getValue

        public Optional<String> getValue​(String option)
        If exists, return the option value as a string.
        Parameters:
        option - The option name
        Returns:
        The option value as a string if it exists, otherwise empty.
      • getValue

        public <T> Optional<T> getValue​(String option,
                                        Function<String,​T> parser)
        If exists, return the option value parsed with the provided parser.
        Parameters:
        option - The option name
        parser - A function to transform the value from string to target type.
        Returns:
        The option value parsed with the provided parser if it exists, otherwise empty.
      • getInt

        public Optional<Integer> getInt​(String option)
        If exists, return the option value as an int.
        Parameters:
        option - The option name
        Returns:
        The option value as an int if it exists, otherwise empty.
      • getFloat

        public Optional<Float> getFloat​(String option)
        If exists, return the option value as a float.
        Parameters:
        option - The option name
        Returns:
        The option value as a float if it exists, otherwise empty.
      • getDouble

        public Optional<Double> getDouble​(String option)
        If exists, return the option value as a double.
        Parameters:
        option - The option name
        Returns:
        The option value as a double if it exists, otherwise empty.
      • getValues

        public Optional<List<String>> getValues​(String option)
        If exists, return the option value as a list of strings, assuming they were provided as a comma separated list.
        Parameters:
        option - The option name
        Returns:
        The option value as a list of strings if it exists, otherwise empty.
      • getEnum

        public <E extends Enum<E>> Optional<E> getEnum​(String option,
                                                       Class<E> clazz)
        If exists, return the option value as an enum.
        Parameters:
        option - The option name
        clazz - The enum class
        Returns:
        The option value as as an enum. if it exists, otherwise empty.
      • hasOption

        public boolean hasOption​(String option)
        Return true if the option is defined.
        Parameters:
        option - The option name
        Returns:
        true if the option is defined.
      • getPath

        public Optional<Path> getPath​(String option)
        If exists, return the option value as a file system Path.
        Parameters:
        option - The option name
        Returns:
        The option value as a double if it exists, otherwise empty.