Class GetOpt

java.lang.Object
com.aoapps.lang.util.GetOpt

public final class GetOpt extends Object
General-purpose command line argument processor. Supports options in the "--option=value" format. boolean options default to true if no value provided. Also supports a single "--" that is used to separate parameters from non-parameters. All arguments start with -- before the "--" must be valid parameters.
Author:
AO Industries, Inc.
  • Method Details

    • parse

      public static <T> T parse(String value, Class<T> type)
      Parses a String value to the provided type. Values are converted by:
      1. Special handling for primitive types
      2. public static valueOf(String) method
      3. public constructor with single String parameter
    • getOpt

      public static <T> T getOpt(String[] args, String name, Class<T> type)
      Gets an argument of the provided type. If the argument is found multiple times, only the most recent value is used. The argument should be in the form --name= value. Boolean arguments are unique in that the value is optional, when not provided it defaults to true. "--" may be used to separate parameters from arguments.
      Parameters:
      args - the values used during the processing of the parameters will be set to null
      Returns:
      the converted value or null if not found
      See Also:
    • getArguments

      public static List<String> getArguments(String[] args)
      Gets all of the non-parameter arguments. If any arguments start with "--" and are not a valid parameter, throws IllegalArgumentException. "--" may be used to separate parameters from arguments. The "--" will be included in the arguments returned.