property annotations: grounds for --list-formatter-properties v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sat, 15 Aug 2015 10:47:56 +0200
branchv_0
changeset 209 8dfe037b3274
parent 208 1a511d321ade
child 210 f8aa3686d512
property annotations: grounds for --list-formatter-properties
java/sql-dk/src/info/globalcode/sql/dk/CLIOptions.java
java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java
java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java
scripts/bash_completion.pl
--- a/java/sql-dk/src/info/globalcode/sql/dk/CLIOptions.java	Sat Aug 15 10:44:36 2015 +0200
+++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIOptions.java	Sat Aug 15 10:47:56 2015 +0200
@@ -47,6 +47,7 @@
 	private String databaseName;
 	private final Set<String> databaseNamesToTest = new LinkedHashSet<>();
 	private final Set<String> databaseNamesToListProperties = new LinkedHashSet<>();
+	private final Set<String> formatterNamesToListProperties = new LinkedHashSet<>();
 	private String namePrefix = DEFAULT_NAME_PREFIX;
 	private String nameSuffix = DEFAULT_NAME_SUFFIX;
 	private String formatterName;
@@ -202,6 +203,7 @@
 	}
 
 	/**
+	 * @param namePrefix
 	 * @see #getNamePrefix()
 	 */
 	public void setNamePrefix(String namePrefix) {
@@ -216,6 +218,7 @@
 	}
 
 	/**
+	 * @param nameSuffix
 	 * @see #getNameSuffix()
 	 */
 	public void setNameSuffix(String nameSuffix) {
@@ -253,7 +256,15 @@
 	public void addDatabaseNameToListProperties(String name) {
 		databaseNamesToListProperties.add(name);
 	}
-	
+
+	public Set<String> getFormatterNamesToListProperties() {
+		return formatterNamesToListProperties;
+	}
+
+	public void addFormatterNameToListProperties(String name) {
+		formatterNamesToListProperties.add(name);
+	}
+
 	public SQLCommand getSQLCommand() {
 		if (namedParameters.isEmpty()) {
 			return new SQLCommandNumbered(sql, numberedParameters);
--- a/java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java	Sat Aug 15 10:44:36 2015 +0200
+++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java	Sat Aug 15 10:47:56 2015 +0200
@@ -126,6 +126,10 @@
 				case Tokens.INFO_FORMATTERS:
 					options.addShowInfo(InfoType.FORMATTERS);
 					break;
+				case Tokens.INFO_FORMATTER_PROPERTIES:
+					options.addShowInfo(InfoType.FORMATTER_PROPERTIES);
+					options.addFormatterNameToListProperties(fetchNext(args, ++i));
+					break;
 				case Tokens.INFO_LICENSE:
 					options.addShowInfo(InfoType.LICENSE);
 					break;
@@ -191,6 +195,7 @@
 		public static final String INFO_JAVA_PROPERTIES = "--list-java-properties"; // bash-completion:option // help: list of Java system properties
 		public static final String INFO_ENVIRONMENT_VARIABLES = "--list-environment-variables"; // bash-completion:option // help: list of environment variables
 		public static final String INFO_FORMATTERS = "--list-formatters"; // bash-completion:option // help: print list of available formatters
+		public static final String INFO_FORMATTER_PROPERTIES = "--list-formatter-properties"; // bash-completion:option // help: print list of available formatter properties
 		public static final String INFO_TYPES = "--list-types"; // bash-completion:option // help: print list of available data types
 		public static final String INFO_JDBC_DRIVERS = "--list-jdbc-drivers"; // bash-completion:option // help: list of available JDBC drivers
 		public static final String INFO_JDBC_PROPERTIES = "--list-jdbc-properties"; // bash-completion:option // help: list of available JDBC properties for given database
--- a/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java	Sat Aug 15 10:44:36 2015 +0200
+++ b/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java	Sat Aug 15 10:47:56 2015 +0200
@@ -176,6 +176,12 @@
 		}
 	}
 
+	private void listFormatterProperties() {
+		for (String name : options.getFormatterNamesToListProperties()) {
+			log.log(Level.SEVERE, "TODO: list formatter properties for {0}", name);
+		}
+	}
+
 	public void listTypes() throws FormatterException, ConfigurationException {
 		ColumnsHeader header = constructHeader(new HeaderField("name", SQLType.VARCHAR), new HeaderField("code", SQLType.INTEGER));
 		List<Object[]> data = new ArrayList<>();
@@ -346,16 +352,13 @@
 		}
 
 		for (final String dbName : options.getDatabaseNamesToTest()) {
-			es.submit(new Runnable() {
-				// TODO: Java 8 – lambda
-				@Override
-				public void run() {
-					final Object[] row = testConnection(dbName);
-					synchronized (currentFormatter) {
-						printRow(currentFormatter, row);
-					}
+			es.submit(() -> {
+				final Object[] row = testConnection(dbName);
+				synchronized (currentFormatter) {
+					printRow(currentFormatter, row);
 				}
-			});
+			}
+			);
 		}
 
 		es.shutdown();
@@ -565,6 +568,12 @@
 						infoLister.listFormatters();
 					}
 				},
+		FORMATTER_PROPERTIES {
+					@Override
+					public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
+						infoLister.listFormatterProperties();
+					}
+				},
 		TYPES {
 					@Override
 					public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
--- a/scripts/bash_completion.pl	Sat Aug 15 10:44:36 2015 +0200
+++ b/scripts/bash_completion.pl	Sat Aug 15 10:47:56 2015 +0200
@@ -56,7 +56,7 @@
 			return 0
 		fi
 		;;
-	--formatter)
+	--formatter | --list-formatter-properties)
 		if [ -f '.$formattersFile.' ]; then
 			COMPREPLY=( $( compgen -W " $( cat '.$formattersFile.' ) " -- $cur ) )
 		else