From 7aed6596bd60172bbebb8b66304794b996108069 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Thu, 27 Jun 2013 05:05:59 +0200 Subject: m bug fix + beginning of java test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/ArgParser.java | 4 +++- src/Test.java | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 src/Test.java (limited to 'src') diff --git a/src/ArgParser.java b/src/ArgParser.java index afac48c..ac37a93 100644 --- a/src/ArgParser.java +++ b/src/ArgParser.java @@ -1039,7 +1039,9 @@ public class ArgParser { sb.append(' '); sb.append(file); } - this.message = sb.toString().substring(1); + this.message = sb.toString(); + if (this.message.length() > 0) + this.message = this.message.substring(1); if (this.unrecognisedCount > 5) { int more = this.unrecognisedCount - 5; diff --git a/src/Test.java b/src/Test.java new file mode 100644 index 0000000..c593b4e --- /dev/null +++ b/src/Test.java @@ -0,0 +1,50 @@ +/** + * argparser – command line argument parser library + * + * Copyright © 2013 Mattias Andrée (maandree@member.fsf.org) + * + * This library is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this library. If not, see . + */ + + +public class Test +{ + public static void main(String... args) + { + System.out.println("Parent: " + ArgParser.parentName()); + + ArgParser parser = new ArgParser("A test for argparser", "test [options] [files]", + "Copyright © 2013 Mattias Andrée (maandree@member.fsf.org)\n" + + "\n" + + "This library is free software: you can redistribute it and/or modify\n" + + "it under the terms of the GNU General Public License as published by\n" + + "the Free Software Foundation, either version 3 of the License, or\n" + + "(at your option) any later version.\n" + + "\n" + + "This library is distributed in the hope that it will be useful,\n" + + "but WITHOUT ANY WARRANTY; without even the implied warranty of\n" + + "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n" + + "GNU General Public License for more details.\n" + + "\n" + + "You should have received a copy of the GNU General Public License\n" + + "along with this library. If not, see .", null, true); + + parser.parse(args); + parser.supportAlternatives(); + + parser.help(); + } + +} + -- cgit v1.2.3-70-g09d2