java/sql-dk/src/info/globalcode/sql/dk/InfoLister.java
author František Kučera <franta-hg@frantovo.cz>
Mon, 16 Dec 2013 20:20:54 +0100
branchv_0
changeset 17 d8ab8aece6f2
parent 16 5b8fcd35d4d6
child 18 7900bb1666f6
permissions -rw-r--r--
license option: --license
franta-hg@16
     1
/**
franta-hg@16
     2
 * SQL-DK
franta-hg@16
     3
 * Copyright © 2013 František Kučera (frantovo.cz)
franta-hg@16
     4
 *
franta-hg@16
     5
 * This program is free software: you can redistribute it and/or modify
franta-hg@16
     6
 * it under the terms of the GNU General Public License as published by
franta-hg@16
     7
 * the Free Software Foundation, either version 3 of the License, or
franta-hg@16
     8
 * (at your option) any later version.
franta-hg@16
     9
 *
franta-hg@16
    10
 * This program is distributed in the hope that it will be useful,
franta-hg@16
    11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
franta-hg@16
    12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
franta-hg@16
    13
 * GNU General Public License for more details.
franta-hg@16
    14
 *
franta-hg@16
    15
 * You should have received a copy of the GNU General Public License
franta-hg@16
    16
 * along with this program. If not, see <http://www.gnu.org/licenses/>.
franta-hg@16
    17
 */
franta-hg@14
    18
package info.globalcode.sql.dk;
franta-hg@14
    19
franta-hg@17
    20
import java.io.BufferedReader;
franta-hg@17
    21
import java.io.InputStreamReader;
franta-hg@14
    22
import java.io.PrintStream;
franta-hg@14
    23
import java.util.EnumSet;
franta-hg@17
    24
import java.util.logging.Level;
franta-hg@17
    25
import java.util.logging.Logger;
franta-hg@14
    26
franta-hg@14
    27
/**
franta-hg@14
    28
 * Displays info like help, version etc.
franta-hg@14
    29
 *
franta-hg@14
    30
 * @author Ing. František Kučera (frantovo.cz)
franta-hg@14
    31
 */
franta-hg@14
    32
public class InfoLister {
franta-hg@14
    33
franta-hg@17
    34
	private static final Logger log = Logger.getLogger(InfoLister.class.getName());
franta-hg@17
    35
	private PrintStream out;
franta-hg@17
    36
franta-hg@17
    37
	public InfoLister(PrintStream out) {
franta-hg@17
    38
		this.out = out;
franta-hg@17
    39
	}
franta-hg@17
    40
franta-hg@17
    41
	public void showInfo(CLIOptions options) {
franta-hg@15
    42
		EnumSet<CLIOptions.INFO_TYPE> infoTypes = options.getShowInfo();
franta-hg@14
    43
		for (CLIOptions.INFO_TYPE infoType : infoTypes) {
franta-hg@14
    44
			switch (infoType) {
franta-hg@14
    45
				/**
franta-hg@14
    46
				 * TODO: implement show info
franta-hg@14
    47
				 */
franta-hg@14
    48
				case FORMATTERS:
franta-hg@17
    49
					println("TODO: list available formatters");
franta-hg@14
    50
					break;
franta-hg@14
    51
				case HELP:
franta-hg@17
    52
					println("TODO: show some help");
franta-hg@14
    53
					break;
franta-hg@14
    54
				case LICENSE:
franta-hg@17
    55
					printLicense();
franta-hg@14
    56
					break;
franta-hg@14
    57
				case TYPES:
franta-hg@17
    58
					println("TODO: list supported types");
franta-hg@14
    59
					break;
franta-hg@14
    60
				case VERSION:
franta-hg@17
    61
					println("TODO: show version");
franta-hg@14
    62
					break;
franta-hg@15
    63
				case DATABASES:
franta-hg@17
    64
					println("TODO: list databases");
franta-hg@15
    65
					break;
franta-hg@15
    66
				case CONNECTION:
franta-hg@17
    67
					println("TODO: test database connection: " + options.getDatabaseNameToTest());
franta-hg@15
    68
					break;
franta-hg@14
    69
				default:
franta-hg@14
    70
					throw new IllegalArgumentException("Unsupported INFO_TYPE: " + infoType);
franta-hg@14
    71
			}
franta-hg@14
    72
		}
franta-hg@14
    73
	}
franta-hg@17
    74
franta-hg@17
    75
	private void printLicense() {
franta-hg@17
    76
		try (BufferedReader license = new BufferedReader(new InputStreamReader(getClass().getClassLoader().getResourceAsStream("info/globalcode/sql/dk/license.txt")))) {
franta-hg@17
    77
			while (true) {
franta-hg@17
    78
				String line = license.readLine();
franta-hg@17
    79
				if (line == null) {
franta-hg@17
    80
					break;
franta-hg@17
    81
				} else {
franta-hg@17
    82
					println(line);
franta-hg@17
    83
				}
franta-hg@17
    84
			}
franta-hg@17
    85
		} catch (Exception e) {
franta-hg@17
    86
			log.log(Level.SEVERE, "Unable to print license. See our website for license information.", e);
franta-hg@17
    87
		}
franta-hg@17
    88
	}
franta-hg@17
    89
franta-hg@17
    90
	private void println(String line) {
franta-hg@17
    91
		out.println(line);
franta-hg@17
    92
	}
franta-hg@14
    93
}