From 8798451585f0e603abb8c8fe7d397efca3d1f175 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 27 Jun 2013 12:08:36 +0200 Subject: add argument checking in java test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/Test.java | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/Test.java b/src/Test.java index e6c5a18..e7be3fd 100644 --- a/src/Test.java +++ b/src/Test.java @@ -50,7 +50,33 @@ public class Test parser.parse(args); parser.supportAlternatives(); - parser.help(); + if (parser.opts.get("-?") != null) + parser.help(); + else if ((parser.unrecognisedCount + parser.files.size() == 0) && (parser.arguments.length > 0)) + { + if (parser.opts.get("--hello") != null) + { for (int i = 0, n = parser.opts.get("--hello").length; i < n; i++) + System.out.println("Hello World"); + } + if (parser.opts.get("-l") != null) + { for (String line : parser.opts.get("--line")) + System.out.println(line); + } + if (parser.opts.get("--lines") != null) + { for (String line : parser.opts.get("--l")) + System.out.println(line); + } + if (parser.opts.get("++hidden") != null) + { System.out.println("Congratulations, you have found the secret option!"); + } + } + else + { System.out.println("Number of unrecognised options: " + parser.unrecognisedCount); + System.out.println("Entered message: " + parser.message); + System.out.println("Entered files:"); + for (String file : parser.files) + System.out.println("\t" + file); + } } } -- cgit v1.2.3-70-g09d2