diff -r 5b8fcd35d4d6 -r d8ab8aece6f2 java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java --- a/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Mon Dec 16 20:01:37 2013 +0100 +++ b/java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java Mon Dec 16 20:20:54 2013 +0100 @@ -17,8 +17,12 @@ */ package info.globalcode.sql.dk; +import java.io.BufferedReader; +import java.io.InputStreamReader; import java.io.PrintStream; import java.util.EnumSet; +import java.util.logging.Level; +import java.util.logging.Logger; /** * Displays info like help, version etc. @@ -27,7 +31,14 @@ */ public class InfoLister { - public void showInfo(CLIOptions options, PrintStream out) { + private static final Logger log = Logger.getLogger(InfoLister.class.getName()); + private PrintStream out; + + public InfoLister(PrintStream out) { + this.out = out; + } + + public void showInfo(CLIOptions options) { EnumSet infoTypes = options.getShowInfo(); for (CLIOptions.INFO_TYPE infoType : infoTypes) { switch (infoType) { @@ -35,29 +46,48 @@ * TODO: implement show info */ case FORMATTERS: - out.println("TODO: list available formatters"); + println("TODO: list available formatters"); break; case HELP: - out.println("TODO: show some help"); + println("TODO: show some help"); break; case LICENSE: - out.println("TODO: show license"); + printLicense(); break; case TYPES: - out.println("TODO: list supported types"); + println("TODO: list supported types"); break; case VERSION: - out.println("TODO: show version"); + println("TODO: show version"); break; case DATABASES: - out.println("TODO: list databases"); + println("TODO: list databases"); break; case CONNECTION: - out.println("TODO: test database connection: " + options.getDatabaseNameToTest()); + println("TODO: test database connection: " + options.getDatabaseNameToTest()); break; default: throw new IllegalArgumentException("Unsupported INFO_TYPE: " + infoType); } } } + + private void printLicense() { + try (BufferedReader license = new BufferedReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("info/globalcode/sql/dk/license.txt")))) { + while (true) { + String line = license.readLine(); + if (line == null) { + break; + } else { + println(line); + } + } + } catch (Exception e) { + log.log(Level.SEVERE, "Unable to print license. See our website for license information.", e); + } + } + + private void println(String line) { + out.println(line); + } }