+ /** Extracts an argument which must be unique. */
+ String singleArg(Map<String, List<String>> options, String arg, boolean mandatory) {
+ List<String> values = options.get(arg);
+ if (values == null || values.size() == 0)
+ if (mandatory)
+ throw new IllegalArgumentException(arg + " argument must be set");
+ else
+ return null;
+ if (values.size() != 1)
+ throw new IllegalArgumentException("One and only one " + arg + " arguments must be specified");
+ return values.get(0);
+ }
+
+ /** Extracts an argument which can have multiple values. */
+ List<String> multiArg(Map<String, List<String>> options, String arg, boolean mandatory) {
+ List<String> values = options.get(arg);
+ if (mandatory && values == null)
+ throw new IllegalArgumentException(arg + " argument must be set");
+ return values != null ? values : new ArrayList<>();
+ }
+
+ /** Delete empty parent directory up to the base directory (included). */
+ void deleteEmptyParents(Path baseDir, Path targetParent) throws IOException {
+ if (!targetParent.startsWith(baseDir))
+ throw new IllegalArgumentException(targetParent + " does not start with " + baseDir);
+ if (!Files.exists(baseDir))
+ return;
+ if (!Files.exists(targetParent)) {
+ deleteEmptyParents(baseDir, targetParent.getParent());
+ return;
+ }