franta-hg@16: /** franta-hg@16: * SQL-DK franta-hg@16: * Copyright © 2013 František Kučera (frantovo.cz) franta-hg@16: * franta-hg@16: * This program is free software: you can redistribute it and/or modify franta-hg@16: * it under the terms of the GNU General Public License as published by franta-hg@16: * the Free Software Foundation, either version 3 of the License, or franta-hg@16: * (at your option) any later version. franta-hg@16: * franta-hg@16: * This program is distributed in the hope that it will be useful, franta-hg@16: * but WITHOUT ANY WARRANTY; without even the implied warranty of franta-hg@16: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the franta-hg@16: * GNU General Public License for more details. franta-hg@16: * franta-hg@16: * You should have received a copy of the GNU General Public License franta-hg@16: * along with this program. If not, see . franta-hg@16: */ franta-hg@14: package info.globalcode.sql.dk; franta-hg@14: franta-hg@17: import java.io.BufferedReader; franta-hg@17: import java.io.InputStreamReader; franta-hg@14: import java.io.PrintStream; franta-hg@14: import java.util.EnumSet; franta-hg@17: import java.util.logging.Level; franta-hg@17: import java.util.logging.Logger; franta-hg@14: franta-hg@14: /** franta-hg@14: * Displays info like help, version etc. franta-hg@14: * franta-hg@14: * @author Ing. František Kučera (frantovo.cz) franta-hg@14: */ franta-hg@14: public class InfoLister { franta-hg@14: franta-hg@17: private static final Logger log = Logger.getLogger(InfoLister.class.getName()); franta-hg@17: private PrintStream out; franta-hg@17: franta-hg@17: public InfoLister(PrintStream out) { franta-hg@17: this.out = out; franta-hg@17: } franta-hg@17: franta-hg@17: public void showInfo(CLIOptions options) { franta-hg@15: EnumSet infoTypes = options.getShowInfo(); franta-hg@14: for (CLIOptions.INFO_TYPE infoType : infoTypes) { franta-hg@14: switch (infoType) { franta-hg@14: /** franta-hg@14: * TODO: implement show info franta-hg@14: */ franta-hg@14: case FORMATTERS: franta-hg@17: println("TODO: list available formatters"); franta-hg@14: break; franta-hg@14: case HELP: franta-hg@17: println("TODO: show some help"); franta-hg@14: break; franta-hg@14: case LICENSE: franta-hg@17: printLicense(); franta-hg@14: break; franta-hg@14: case TYPES: franta-hg@17: println("TODO: list supported types"); franta-hg@14: break; franta-hg@14: case VERSION: franta-hg@17: println("TODO: show version"); franta-hg@14: break; franta-hg@15: case DATABASES: franta-hg@17: println("TODO: list databases"); franta-hg@15: break; franta-hg@15: case CONNECTION: franta-hg@17: println("TODO: test database connection: " + options.getDatabaseNameToTest()); franta-hg@15: break; franta-hg@14: default: franta-hg@14: throw new IllegalArgumentException("Unsupported INFO_TYPE: " + infoType); franta-hg@14: } franta-hg@14: } franta-hg@14: } franta-hg@17: franta-hg@17: private void printLicense() { franta-hg@17: try (BufferedReader license = new BufferedReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("info/globalcode/sql/dk/license.txt")))) { franta-hg@17: while (true) { franta-hg@17: String line = license.readLine(); franta-hg@17: if (line == null) { franta-hg@17: break; franta-hg@17: } else { franta-hg@17: println(line); franta-hg@17: } franta-hg@17: } franta-hg@17: } catch (Exception e) { franta-hg@17: log.log(Level.SEVERE, "Unable to print license. See our website for license information.", e); franta-hg@17: } franta-hg@17: } franta-hg@17: franta-hg@17: private void println(String line) { franta-hg@17: out.println(line); franta-hg@17: } franta-hg@14: }