formatted output for: --list-formatters --list-databases v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Thu, 26 Dec 2013 22:18:24 +0100
branchv_0
changeset 72fc9fc1f26b88
parent 71 e5d04a68ce1e
child 73 d32fd50d3c2c
formatted output for: --list-formatters --list-databases
java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java
java/sql-dk/test/info/globalcode/sql/dk/CLIParserTest.java
     1.1 --- a/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java	Thu Dec 26 21:48:59 2013 +0100
     1.2 +++ b/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java	Thu Dec 26 22:18:24 2013 +0100
     1.3 @@ -22,7 +22,6 @@
     1.4  import info.globalcode.sql.dk.configuration.ConfigurationProvider;
     1.5  import info.globalcode.sql.dk.configuration.DatabaseDefinition;
     1.6  import info.globalcode.sql.dk.configuration.FormatterDefinition;
     1.7 -import static info.globalcode.sql.dk.Functions.rpad;
     1.8  import info.globalcode.sql.dk.formatting.ColumnsHeader;
     1.9  import info.globalcode.sql.dk.formatting.Formatter;
    1.10  import info.globalcode.sql.dk.formatting.FormatterContext;
    1.11 @@ -81,23 +80,28 @@
    1.12  		}
    1.13  	}
    1.14  
    1.15 -	private void listFormatters() throws ConfigurationException {
    1.16 +	private void listFormatters() throws ConfigurationException, FormatterException {
    1.17 +		ColumnsHeader header = constructHeader(
    1.18 +				new HeaderField("name", SQLType.VARCHAR),
    1.19 +				new HeaderField("built_in", SQLType.BOOLEAN),
    1.20 +				new HeaderField("default", SQLType.BOOLEAN),
    1.21 +				new HeaderField("class_name", SQLType.VARCHAR));
    1.22 +		List<Object[]> data = new ArrayList<>();
    1.23 +
    1.24 +		String defaultFormatter = configurationProvider.getConfiguration().getDefaultFormatter();
    1.25 +		defaultFormatter = defaultFormatter == null ? Configuration.DEFAULT_FORMATTER : defaultFormatter;
    1.26 +
    1.27  		for (FormatterDefinition fd : configurationProvider.getConfiguration().getBuildInFormatters()) {
    1.28 -			log.log(Level.INFO, "Built-in formatter:   {0} implemented by class: {1}", new Object[]{rpad(fd.getName(), 16), fd.getClassName()});
    1.29 +			data.add(new Object[]{fd.getName(), true, defaultFormatter.equals(fd.getName()), fd.getClassName()});
    1.30  		}
    1.31 -		List<FormatterDefinition> configuredFormatters = configurationProvider.getConfiguration().getFormatters();
    1.32 -		for (FormatterDefinition fd : configuredFormatters) {
    1.33 -			log.log(Level.INFO, "Configured formatter: {0} implemented by class: {1}", new Object[]{rpad(fd.getName(), 16), fd.getClassName()});
    1.34 +
    1.35 +		for (FormatterDefinition fd : configurationProvider.getConfiguration().getFormatters()) {
    1.36 +			data.add(new Object[]{fd.getName(), false, defaultFormatter.equals(fd.getName()), fd.getClassName()});
    1.37  		}
    1.38 -		if (configuredFormatters.isEmpty()) {
    1.39 -			log.log(Level.INFO, "No other formatters are configured");
    1.40 -		}
    1.41 -		String configuredDefaultFormatter = configurationProvider.getConfiguration().getDefaultFormatter();
    1.42 -		if (configuredDefaultFormatter == null) {
    1.43 -			log.log(Level.INFO, "Built-in default formatter: {0}", Configuration.DEFAULT_FORMATTER);
    1.44 -		} else {
    1.45 -			log.log(Level.INFO, "Configured default formatter: {0}", configuredDefaultFormatter);
    1.46 -		}
    1.47 +
    1.48 +		printTable(formatter, header, data);
    1.49 +
    1.50 +
    1.51  	}
    1.52  
    1.53  	public void listTypes() throws FormatterException, ConfigurationException {
    1.54 @@ -109,15 +113,23 @@
    1.55  		printTable(formatter, header, data);
    1.56  	}
    1.57  
    1.58 -	public void listDatabases() throws ConfigurationException {
    1.59 +	public void listDatabases() throws ConfigurationException, FormatterException {
    1.60 +		ColumnsHeader header = constructHeader(
    1.61 +				new HeaderField("database_name", SQLType.VARCHAR),
    1.62 +				new HeaderField("user_name", SQLType.VARCHAR),
    1.63 +				new HeaderField("database_url", SQLType.VARCHAR));
    1.64 +		List<Object[]> data = new ArrayList<>();
    1.65 +
    1.66  		final List<DatabaseDefinition> configuredDatabases = configurationProvider.getConfiguration().getDatabases();
    1.67  		if (configuredDatabases.isEmpty()) {
    1.68  			log.log(Level.WARNING, "No databases are configured.");
    1.69  		} else {
    1.70  			for (DatabaseDefinition dd : configuredDatabases) {
    1.71 -				log.log(Level.INFO, "Configured database: {0}", dd.getName());
    1.72 +				data.add(new Object[]{dd.getName(), dd.getUserName(), dd.getUrl()});
    1.73  			}
    1.74  		}
    1.75 +
    1.76 +		printTable(formatter, header, data);
    1.77  	}
    1.78  
    1.79  	public void testConnection() {
     2.1 --- a/java/sql-dk/test/info/globalcode/sql/dk/CLIParserTest.java	Thu Dec 26 21:48:59 2013 +0100
     2.2 +++ b/java/sql-dk/test/info/globalcode/sql/dk/CLIParserTest.java	Thu Dec 26 22:18:24 2013 +0100
     2.3 @@ -19,6 +19,7 @@
     2.4  
     2.5  import info.globalcode.sql.dk.CLIParser.Tokens;
     2.6  import static info.globalcode.sql.dk.CLIParser.TYPE_NAME_SEPARATOR;
     2.7 +import info.globalcode.sql.dk.InfoLister.InfoType;
     2.8  import java.util.Collection;
     2.9  import static org.testng.Assert.*;
    2.10  import org.testng.annotations.BeforeMethod;
    2.11 @@ -184,6 +185,6 @@
    2.12  
    2.13  		assertEquals(options.getMode(), CLIOptions.MODE.JUST_SHOW_INFO);
    2.14  		assertEquals(options.getShowInfo().size(), 1);
    2.15 -		assertTrue(options.getShowInfo().contains(CLIOptions.InfoType.HELP));
    2.16 +		assertTrue(options.getShowInfo().contains(InfoType.HELP));
    2.17  	}
    2.18  }
    2.19 \ No newline at end of file