class OptionsParser {

  public S3MapReduceCpOptions parse(String... args) throws IllegalArgumentException {
    try {
      jCommander.parse(args);
    } catch (Exception e) {
      throw new IllegalArgumentException("Unable to parse arguments: " + Arrays.toString(args), e);
    }

    if (options.isHelp()) {
      return options;
    }

    for (Path source : options.getSources()) {
      if (!source.isAbsolute()) {
        throw new IllegalArgumentException("Source paths must be absolute: " + Arrays.toString(args));
      }
    }

    if (!options.getTarget().isAbsolute()) {
      throw new IllegalArgumentException("Destination URI must be absolute: " + Arrays.toString(args));
    }

    if (options.getCredentialsProvider() != null && !options.getCredentialsProvider().isAbsolute()) {
      throw new IllegalArgumentException("Credentials provider URI must be absolute: " + Arrays.toString(args));
    }

    if (options.getMaxMaps() <= 0) {
      options.setMaxMaps(1);
    }

    if (options.getLogPath() != null && !options.getLogPath().isAbsolute()) {
      throw new IllegalArgumentException("Log path must be absolute: " + Arrays.toString(args));
    }

    return options;
  }

}