class CommandParser {

  public static HashMap<String, Object> parse(String[] _args, Options options)
      throws CommandLineParserException {
    final CommandLineParser parser = new DefaultParser();
    CommandLine cmd = null;
    try {
      cmd = parser.parse(options, _args, true);
    } catch (ParseException e) {
      throw new CommandLineParserException(e.getMessage());
    }

    HashMap<String, Object> mapOptionValues = new HashMap<>();
    Collection<Option> optionCollection = options.getOptions();
    for (Option option : optionCollection) {
      if (option.hasArg()) {
        mapOptionValues.put(option.getOpt(), cmd.getOptionValue(option.getOpt()));
      } else {
        if (cmd.hasOption(option.getOpt()) || cmd.hasOption(option.getLongOpt())) {
          mapOptionValues.put(option.getOpt(), true);
        } else {
          mapOptionValues.put(option.getOpt(), false);
        }
      }
    }

    return mapOptionValues;
  }

}