package exporter.examples;

import java.util.Date;

import org.apache.commons.cli.BasicParser;
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;

// Example of application using CLI
public class DateApp {

	public static void main(String[] args) throws ParseException {

		// create Options object
		Options options = new Options();

		// add time option
		options.addOption("time", false, "displays current time");
		// add date option
		options.addOption("date", false, "displays current time");

		// There are several implementations to parse command line arguments,
		// the recommended one is the DefaultParser but I can't find it in the
		// library, probably outdated documentation
		BasicParser parser = new BasicParser();
		CommandLine cmd = parser.parse(options, args);

		if (cmd.hasOption("time")) { // java DateApp -time

			Date date = new Date();
			// current time
			String str = String.format("Current Time : %tT", date);
			System.out.printf(str);

		} else if (cmd.hasOption("date")) { // java DateApp -date

			Date date = new Date();
			// current date
			String str = String.format("Current Date : %tF", date);
			System.out.printf(str);

		}

	}
}

@@ -37,16 +37,72 @@
 ava.
-util.Dat
+text.DateFormat;%0Aimport java.util.Date;%0Aimport java.util.TimeZon
 e;%0A%0A
@@ -624,16 +624,90 @@
  time%22);
+%0A%09%09// add local option%0A%09%09options.addOption(%22local%22, true, %22country code%22);
 %0A%0A%09%09// T
@@ -1364,16 +1364,505 @@
 (str);%0A%0A
+%09%09%7D else if (cmd.hasOption(%22local%22)) %7B%0A%09%09%09// get local option value%0A%09%09%09String countryCode = cmd.getOptionValue(%22local%22);%0A%0A%09%09%09// for demonstration purposes it only supports %22America/New_York%22%0A%09%09%09if (countryCode.equals(%22America/New_York%22)) %7B%0A%09%09%09%09Date date = new Date();%0A%09%09%09%09DateFormat nyDf = DateFormat.getDateTimeInstance(%0A%09%09%09%09%09%09DateFormat.FULL, DateFormat.FULL);%0A%09%09%09%09nyDf.setTimeZone(TimeZone.getTimeZone(%22America/New_York%22));%0A%0A%09%09%09%09System.out.println(%22NY    : %22 + nyDf.format(date));%0A%09%09%09%7D%0A
 %09%09%7D%0A%0A%09%7D%0A

Add example where the argument value is used