--- 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<Object[]> 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()});
- }
- List<FormatterDefinition> 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()});
+ data.add(new Object[]{fd.getName(), true, defaultFormatter.equals(fd.getName()), fd.getClassName()});
}
- if (configuredFormatters.isEmpty()) {
- log.log(Level.INFO, "No other formatters are configured");
+
+ for (FormatterDefinition fd : configurationProvider.getConfiguration().getFormatters()) {
+ data.add(new Object[]{fd.getName(), false, defaultFormatter.equals(fd.getName()), fd.getClassName()});
}
- 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<Object[]> data = new ArrayList<>();
+
final List<DatabaseDefinition> 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() {
--- 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