Skip to content

Commit

Permalink
Issue #81. Print supported config formats
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray authored and gunnarmorling committed Feb 2, 2021
1 parent 3e823f5 commit 1b96781
Showing 1 changed file with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@
import com.beust.jcommander.JCommander;
import com.beust.jcommander.ParameterException;
import org.moditect.layrry.Layrry;
import org.moditect.layrry.config.LayersConfigParser;
import org.moditect.layrry.launcher.internal.Args;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.LinkedHashSet;
import java.util.ServiceLoader;
import java.util.Set;

/**
* The main entry point for using Layrry on the command line. Expects the layers config file to be passed in:
Expand Down Expand Up @@ -53,12 +57,12 @@ public static void launch(String... args) throws Exception {
try {
jCommander.parse(args);
} catch (ParameterException e) {
jCommander.usage();
printUsage(jCommander);
return;
}

if (arguments.isHelp()) {
jCommander.usage();
printUsage(jCommander);
return;
}

Expand Down Expand Up @@ -114,4 +118,25 @@ private static URL toUrl(String input) {
return null;
}
}

private static void printUsage(JCommander jCommander) {
jCommander.usage();

StringBuilder sb = new StringBuilder("Supported config formats are ")
.append(getSupportedConfigFormats());
jCommander.getConsole().println(sb.toString());
}

private static Set<String> getSupportedConfigFormats() {
Set<String> extensions = new LinkedHashSet<>();

ServiceLoader<LayersConfigParser> parsers = ServiceLoader.load(LayersConfigParser.class,
LayrryLauncher.class.getClassLoader());

for (LayersConfigParser parser : parsers) {
extensions.add("." + parser.getPreferredFileExtension());
}

return extensions;
}
}

0 comments on commit 1b96781

Please sign in to comment.