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