From 169853692017480d065208cb768b83f1014cf68a Mon Sep 17 00:00:00 2001 From: Andreas Baumann Date: Wed, 26 Feb 2020 07:34:48 +0100 Subject: added jargs, made it build again, but it bases on a really old Lucene 3.5.0, so it's no longer of any use for modern Lucene/SolR/ElasticSearch --- .../jargs-1.0/examples/gnu/CustomOptionTest.java | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 3rdParty/jargs-1.0/examples/gnu/CustomOptionTest.java (limited to '3rdParty/jargs-1.0/examples/gnu/CustomOptionTest.java') diff --git a/3rdParty/jargs-1.0/examples/gnu/CustomOptionTest.java b/3rdParty/jargs-1.0/examples/gnu/CustomOptionTest.java new file mode 100644 index 0000000..2a1c45f --- /dev/null +++ b/3rdParty/jargs-1.0/examples/gnu/CustomOptionTest.java @@ -0,0 +1,73 @@ +package jargs.examples.gnu; + +import jargs.gnu.CmdLineParser; +import java.text.DateFormat; +import java.text.ParseException; +import java.util.Locale; +import java.util.Date; + +public class CustomOptionTest { + + private static void printUsage() { + System.err.println("usage: prog [{-d,--date} date]"); + } + + + /** + * A custom type of command line option corresponding to a short + * date value, e.g. . + */ + public static class ShortDateOption extends CmdLineParser.Option { + public ShortDateOption( char shortForm, String longForm ) { + super(shortForm, longForm, true); + } + protected Object parseValue( String arg, Locale locale ) + throws CmdLineParser.IllegalOptionValueException { + try { + DateFormat dateFormat = + DateFormat.getDateInstance(DateFormat.SHORT, locale); + return dateFormat.parse(arg); + } + catch (ParseException e) { + throw new CmdLineParser.IllegalOptionValueException(this, arg); + } + } + } + + public static void main( String[] args ) { + CmdLineParser parser = new CmdLineParser(); + CmdLineParser.Option date = + parser.addOption(new ShortDateOption('d', "date")); + + try { + parser.parse(args); + } + catch ( CmdLineParser.OptionException e ) { + System.err.println(e.getMessage()); + printUsage(); + System.exit(2); + } + + // Extract the values entered for the various options -- if the + // options were not specified, the corresponding values will be + // null. + Date dateValue = (Date)parser.getOptionValue(date); + + // For testing purposes, we just print out the option values + System.out.println("date: " + dateValue); + + // Extract the trailing command-line arguments ('a_number') in the + // usage string above. + String[] otherArgs = parser.getRemainingArgs(); + System.out.println("remaining args: "); + for ( int i = 0; i < otherArgs.length; ++i ) { + System.out.println(otherArgs[i]); + } + + // In a real program, one would pass the option values and other + // arguments to a function that does something more useful. + + System.exit(0); + } + +} -- cgit v1.2.3-54-g00ecf