diff -r 0befec5034c2 -r 02c8eaa425e8 java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java --- a/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Thu Dec 26 21:18:54 2013 +0100 +++ b/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Thu Dec 26 21:47:33 2013 +0100 @@ -31,6 +31,8 @@ import java.io.InputStreamReader; import java.io.PrintStream; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.EnumSet; import java.util.List; import java.util.logging.Level; import java.util.logging.Logger; @@ -47,6 +49,7 @@ private PrintStream out; private ConfigurationProvider configurationProvider; private CLIOptions options; + private Formatter formatter; public InfoLister(PrintStream out, ConfigurationProvider configurationProvider, CLIOptions options) { this.out = out; @@ -54,7 +57,31 @@ this.options = options; } - public void listFormatters() throws ConfigurationException { + public void showInfo() throws ConfigurationException, FormatterException { + EnumSet commands = options.getShowInfo(); + + for (InfoType infoType : commands) { + switch (infoType) { + // only these needs formatted output + case CONNECTION: + case DATABASES: + case FORMATTERS: + case TYPES: + formatter = getFormatter(); + formatter.writeStartDatabase(new DatabaseDefinition()); + } + } + + for (InfoType infoType : commands) { + infoType.showInfo(this); + } + + if (formatter != null) { + formatter.writeEndDatabase(); + } + } + + private void listFormatters() throws ConfigurationException { for (FormatterDefinition fd : configurationProvider.getConfiguration().getBuildInFormatters()) { log.log(Level.INFO, "Built-in formatter: {0} implemented by class: {1}", new Object[]{rpad(fd.getName(), 16), fd.getClassName()}); } @@ -73,7 +100,13 @@ } } - public void listTypes() throws FormatterException { + public void listTypes() throws FormatterException, ConfigurationException { + ColumnsHeader header = constructHeader(new HeaderField("name", SQLType.VARCHAR), new HeaderField("code", SQLType.INTEGER)); + List data = new ArrayList<>(); + for (SQLType sqlType : SQLType.values()) { + data.add(new Object[]{sqlType.name(), sqlType.getCode()}); + } + printTable(formatter, header, data); } public void listDatabases() throws ConfigurationException { @@ -199,19 +232,19 @@ }, FORMATTERS { @Override - public void showInfo(InfoLister infoLister) throws ConfigurationException { + public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException { infoLister.listFormatters(); } }, TYPES { @Override - public void showInfo(InfoLister infoLister) throws FormatterException { + public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException { infoLister.listTypes(); } }, DATABASES { @Override - public void showInfo(InfoLister infoLister) throws ConfigurationException { + public void showInfo(InfoLister infoLister) throws FormatterException, ConfigurationException { infoLister.listDatabases(); } },