From: Svjatoslav Agejenko Date: Sun, 27 Jan 2013 10:11:46 +0000 (+0200) Subject: support for commandline arguments X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=commitdiff_plain;h=0d46abdbadb1d25f38408c5ba9958f9a8bf31014;p=instantlauncher.git support for commandline arguments --- diff --git a/src/main/java/eu/svjatoslav/instantlauncher/CommandlineHandler.java b/src/main/java/eu/svjatoslav/instantlauncher/CommandlineHandler.java new file mode 100755 index 0000000..2b71669 --- /dev/null +++ b/src/main/java/eu/svjatoslav/instantlauncher/CommandlineHandler.java @@ -0,0 +1,28 @@ +package eu.svjatoslav.instantlauncher; + +import eu.svjatoslav.commons.commandline.parameterparser.Parameter; +import eu.svjatoslav.commons.commandline.parameterparser.Parser; + +public class CommandlineHandler { + + Parameter helpParameter = new Parameter("Show commandline optons help", "-h", "--help"); + private final Parser parser; + + public CommandlineHandler() { + + parser = new Parser(); + parser.addParameter(helpParameter); + + } + + public void parseCommandlineArguments(final String[] args) { + + if (!parser.parse(args)) + return; + + if (helpParameter.isParameterSpecified()) { + parser.showHelp(); + System.exit(0); + } + } +} diff --git a/src/main/java/eu/svjatoslav/instantlauncher/Main.java b/src/main/java/eu/svjatoslav/instantlauncher/Main.java index aede86b..47f1cba 100755 --- a/src/main/java/eu/svjatoslav/instantlauncher/Main.java +++ b/src/main/java/eu/svjatoslav/instantlauncher/Main.java @@ -7,6 +7,10 @@ public class Main { public static void main(final String[] args) { try { + + final CommandlineHandler commandlineHandler = new CommandlineHandler(); + commandlineHandler.parseCommandlineArguments(args); + final InstantLauncher instantLauncher = new InstantLauncher(); instantLauncher.run(); } catch (final Exception e) {