# HG changeset patch # User František Kučera # Date 1388092704 -3600 # Node ID fc9fc1f26b882d140cb5a38d4fbc699d51207b7f # Parent e5d04a68ce1e36da47e813f3e12a072658f83d5a formatted output for: --list-formatters --list-databases diff -r e5d04a68ce1e -r fc9fc1f26b88 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:48:59 2013 +0100 +++ b/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Thu Dec 26 22:18:24 2013 +0100 @@ -22,7 +22,6 @@ import info.globalcode.sql.dk.configuration.ConfigurationProvider; import info.globalcode.sql.dk.configuration.DatabaseDefinition; import info.globalcode.sql.dk.configuration.FormatterDefinition; -import static info.globalcode.sql.dk.Functions.rpad; import info.globalcode.sql.dk.formatting.ColumnsHeader; import info.globalcode.sql.dk.formatting.Formatter; import info.globalcode.sql.dk.formatting.FormatterContext; @@ -81,23 +80,28 @@ } } - private void listFormatters() throws ConfigurationException { + private void listFormatters() throws ConfigurationException, FormatterException { + ColumnsHeader header = constructHeader( + new HeaderField("name", SQLType.VARCHAR), + new HeaderField("built_in", SQLType.BOOLEAN), + new HeaderField("default", SQLType.BOOLEAN), + new HeaderField("class_name", SQLType.VARCHAR)); + List data = new ArrayList<>(); + + String defaultFormatter = configurationProvider.getConfiguration().getDefaultFormatter(); + defaultFormatter = defaultFormatter == null ? Configuration.DEFAULT_FORMATTER : defaultFormatter; + 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()}); + data.add(new Object[]{fd.getName(), true, defaultFormatter.equals(fd.getName()), fd.getClassName()}); } - List configuredFormatters = configurationProvider.getConfiguration().getFormatters(); - for (FormatterDefinition fd : configuredFormatters) { - log.log(Level.INFO, "Configured formatter: {0} implemented by class: {1}", new Object[]{rpad(fd.getName(), 16), fd.getClassName()}); + + for (FormatterDefinition fd : configurationProvider.getConfiguration().getFormatters()) { + data.add(new Object[]{fd.getName(), false, defaultFormatter.equals(fd.getName()), fd.getClassName()}); } - if (configuredFormatters.isEmpty()) { - log.log(Level.INFO, "No other formatters are configured"); - } - String configuredDefaultFormatter = configurationProvider.getConfiguration().getDefaultFormatter(); - if (configuredDefaultFormatter == null) { - log.log(Level.INFO, "Built-in default formatter: {0}", Configuration.DEFAULT_FORMATTER); - } else { - log.log(Level.INFO, "Configured default formatter: {0}", configuredDefaultFormatter); - } + + printTable(formatter, header, data); + + } public void listTypes() throws FormatterException, ConfigurationException { @@ -109,15 +113,23 @@ printTable(formatter, header, data); } - public void listDatabases() throws ConfigurationException { + public void listDatabases() throws ConfigurationException, FormatterException { + ColumnsHeader header = constructHeader( + new HeaderField("database_name", SQLType.VARCHAR), + new HeaderField("user_name", SQLType.VARCHAR), + new HeaderField("database_url", SQLType.VARCHAR)); + List data = new ArrayList<>(); + final List configuredDatabases = configurationProvider.getConfiguration().getDatabases(); if (configuredDatabases.isEmpty()) { log.log(Level.WARNING, "No databases are configured."); } else { for (DatabaseDefinition dd : configuredDatabases) { - log.log(Level.INFO, "Configured database: {0}", dd.getName()); + data.add(new Object[]{dd.getName(), dd.getUserName(), dd.getUrl()}); } } + + printTable(formatter, header, data); } public void testConnection() { diff -r e5d04a68ce1e -r fc9fc1f26b88 java/sql-dk/test/info/globalcode/sql/dk/CLIParserTest.java --- a/java/sql-dk/test/info/globalcode/sql/dk/CLIParserTest.java Thu Dec 26 21:48:59 2013 +0100 +++ b/java/sql-dk/test/info/globalcode/sql/dk/CLIParserTest.java Thu Dec 26 22:18:24 2013 +0100 @@ -19,6 +19,7 @@ import info.globalcode.sql.dk.CLIParser.Tokens; import static info.globalcode.sql.dk.CLIParser.TYPE_NAME_SEPARATOR; +import info.globalcode.sql.dk.InfoLister.InfoType; import java.util.Collection; import static org.testng.Assert.*; import org.testng.annotations.BeforeMethod; @@ -184,6 +185,6 @@ assertEquals(options.getMode(), CLIOptions.MODE.JUST_SHOW_INFO); assertEquals(options.getShowInfo().size(), 1); - assertTrue(options.getShowInfo().contains(CLIOptions.InfoType.HELP)); + assertTrue(options.getShowInfo().contains(InfoType.HELP)); } } \ No newline at end of file