1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java Thu Dec 26 21:18:54 2013 +0100
1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/CLIStarter.java Thu Dec 26 21:47:33 2013 +0100
1.3 @@ -98,9 +98,7 @@
1.4 if (!options.getShowInfo().isEmpty()) {
1.5 PrintStream infoOut = mode == MODE.JUST_SHOW_INFO ? System.out : System.err;
1.6 InfoLister infoLister = new InfoLister(infoOut, this, options);
1.7 - for (InfoLister.InfoType infoType : options.getShowInfo()) {
1.8 - infoType.showInfo(infoLister);
1.9 - }
1.10 + infoLister.showInfo();
1.11 }
1.12
1.13 switch (mode) {
2.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Thu Dec 26 21:18:54 2013 +0100
2.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Thu Dec 26 21:47:33 2013 +0100
2.3 @@ -31,6 +31,8 @@
2.4 import java.io.InputStreamReader;
2.5 import java.io.PrintStream;
2.6 import java.sql.SQLException;
2.7 +import java.util.ArrayList;
2.8 +import java.util.EnumSet;
2.9 import java.util.List;
2.10 import java.util.logging.Level;
2.11 import java.util.logging.Logger;
2.12 @@ -47,6 +49,7 @@
2.13 private PrintStream out;
2.14 private ConfigurationProvider configurationProvider;
2.15 private CLIOptions options;
2.16 + private Formatter formatter;
2.17
2.18 public InfoLister(PrintStream out, ConfigurationProvider configurationProvider, CLIOptions options) {
2.19 this.out = out;
2.20 @@ -54,7 +57,31 @@
2.21 this.options = options;
2.22 }
2.23
2.24 - public void listFormatters() throws ConfigurationException {
2.25 + public void showInfo() throws ConfigurationException, FormatterException {
2.26 + EnumSet<InfoType> commands = options.getShowInfo();
2.27 +
2.28 + for (InfoType infoType : commands) {
2.29 + switch (infoType) {
2.30 + // only these needs formatted output
2.31 + case CONNECTION:
2.32 + case DATABASES:
2.33 + case FORMATTERS:
2.34 + case TYPES:
2.35 + formatter = getFormatter();
2.36 + formatter.writeStartDatabase(new DatabaseDefinition());
2.37 + }
2.38 + }
2.39 +
2.40 + for (InfoType infoType : commands) {
2.41 + infoType.showInfo(this);
2.42 + }
2.43 +
2.44 + if (formatter != null) {
2.45 + formatter.writeEndDatabase();
2.46 + }
2.47 + }
2.48 +
2.49 + private void listFormatters() throws ConfigurationException {
2.50 for (FormatterDefinition fd : configurationProvider.getConfiguration().getBuildInFormatters()) {
2.51 log.log(Level.INFO, "Built-in formatter: {0} implemented by class: {1}", new Object[]{rpad(fd.getName(), 16), fd.getClassName()});
2.52 }
2.53 @@ -73,7 +100,13 @@
2.54 }
2.55 }
2.56
2.57 - public void listTypes() throws FormatterException {
2.58 + public void listTypes() throws FormatterException, ConfigurationException {
2.59 + ColumnsHeader header = constructHeader(new HeaderField("name", SQLType.VARCHAR), new HeaderField("code", SQLType.INTEGER));
2.60 + List<Object[]> data = new ArrayList<>();
2.61 + for (SQLType sqlType : SQLType.values()) {
2.62 + data.add(new Object[]{sqlType.name(), sqlType.getCode()});
2.63 + }
2.64 + printTable(formatter, header, data);
2.65 }
2.66
2.67 public void listDatabases() throws ConfigurationException {
2.68 @@ -199,19 +232,19 @@
2.69 },
2.70 FORMATTERS {
2.71 @Override
2.72 - public void showInfo(InfoLister infoLister) throws ConfigurationException {
2.73 + public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
2.74 infoLister.listFormatters();
2.75 }
2.76 },
2.77 TYPES {
2.78 @Override
2.79 - public void showInfo(InfoLister infoLister) throws FormatterException {
2.80 + public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
2.81 infoLister.listTypes();
2.82 }
2.83 },
2.84 DATABASES {
2.85 @Override
2.86 - public void showInfo(InfoLister infoLister) throws ConfigurationException {
2.87 + public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException {
2.88 infoLister.listDatabases();
2.89 }
2.90 },