java/sql-dk/src/info/globalcode/sql/dk/CLIParser.java
author František Kučera <franta-hg@frantovo.cz>
Mon, 16 Dec 2013 15:29:02 +0100
branchv_0
changeset 15 bbd335b5410c
parent 14 189b1260b942
child 16 5b8fcd35d4d6
permissions -rw-r--r--
show info basics: list databases + test connection
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     1
package info.globalcode.sql.dk;
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
     2
4
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
     3
import java.sql.Types;
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
     4
import java.util.ArrayList;
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
     5
import java.util.Collections;
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
     6
import java.util.HashMap;
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
     7
import java.util.List;
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
     8
import java.util.Map;
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
     9
1
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    10
/**
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    11
 *
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    12
 * @author Ing. František Kučera (frantovo.cz)
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    13
 */
5
26223eb63851 more OOP
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    14
public class CLIParser {
1
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    15
4
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    16
	public static final String TYPE_NAME_SEPARATOR = ":";
5
26223eb63851 more OOP
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    17
	private final Map<String, Integer> types;
4
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    18
5
26223eb63851 more OOP
František Kučera <franta-hg@frantovo.cz>
parents: 4
diff changeset
    19
	public CLIParser() {
4
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    20
		Map<String, Integer> m = new HashMap<>();
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    21
		m.put("int", Types.INTEGER);
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    22
		m.put("string", Types.VARCHAR);
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    23
		m.put("boolean", Types.BOOLEAN);
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    24
		/**
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    25
		 * TODO: more types
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    26
		 */
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    27
		types = Collections.unmodifiableMap(m);
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    28
	}
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    29
9
2ec52027b97f better exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    30
	public CLIOptions parseOptions(String[] args) throws CLIParserException {
1
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    31
		CLIOptions options = new CLIOptions();
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    32
4
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    33
		List<Integer> numberedTypes = new ArrayList<>();
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    34
		Map<String, Integer> namedTypes = new HashMap<>();
2
72da10f632b5 more code
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    35
1
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    36
		for (int i = 0; i < args.length; i++) {
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    37
			String arg = args[i];
2
72da10f632b5 more code
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    38
			switch (arg) {
72da10f632b5 more code
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    39
				case Tokens.TYPES:
8
4507cb9a0cf1 more exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    40
					String typesString = fetchNext(args, ++i);
4
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    41
10
f528406f33f4 unit-test: types
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
    42
					for (String oneType : typesString.split(",")) {
4
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    43
						int sepatratorIndex = oneType.indexOf(TYPE_NAME_SEPARATOR);
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    44
						if (sepatratorIndex == -1) {
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    45
							numberedTypes.add(getType(oneType));
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    46
						} else {
12
2dcb67d90fd2 unit-test: names, types, prefix
František Kučera <franta-hg@frantovo.cz>
parents: 10
diff changeset
    47
							String namePart = oneType.substring(0, sepatratorIndex).trim();
4
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    48
							String typePart = oneType.substring(sepatratorIndex + TYPE_NAME_SEPARATOR.length(), oneType.length());
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    49
							namedTypes.put(namePart, getType(typePart));
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    50
						}
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    51
					}
2
72da10f632b5 more code
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    52
					break;
72da10f632b5 more code
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    53
				case Tokens.NAME_PREFIX:
8
4507cb9a0cf1 more exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    54
					options.setNamePrefix(fetchNext(args, ++i));
2
72da10f632b5 more code
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    55
					break;
1
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    56
				case Tokens.DB:
8
4507cb9a0cf1 more exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    57
					options.setDatabaseName(fetchNext(args, ++i));
1
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    58
					break;
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    59
				case Tokens.SQL:
8
4507cb9a0cf1 more exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    60
					options.setSql(fetchNext(args, ++i));
2
72da10f632b5 more code
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    61
					options.setCommandType(CLIOptions.COMMAND_TYPE.QUERY);
1
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    62
					break;
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    63
				case Tokens.SQL_UPDATE:
2
72da10f632b5 more code
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    64
				case Tokens.SQL_INSERT:
8
4507cb9a0cf1 more exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    65
					options.setSql(fetchNext(args, ++i));
2
72da10f632b5 more code
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    66
					options.setCommandType(CLIOptions.COMMAND_TYPE.UPDATE);
1
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    67
					break;
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    68
				case Tokens.BATCH:
2
72da10f632b5 more code
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
    69
					options.setBatch(true);
1
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    70
					break;
4
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    71
				case Tokens.DATA: // --data is the last option
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    72
					for (i++; i < args.length; i++) {
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    73
						arg = args[i];
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    74
8
4507cb9a0cf1 more exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    75
						if (arg.startsWith(options.getNamePrefix())) { // Named parameters:
4
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    76
							String paramName = arg.substring(options.getNamePrefix().length());
8
4507cb9a0cf1 more exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    77
							String paramValue = fetchNext(args, ++i);
4
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    78
							options.addNamedParameter(new NamedParameter(paramName, paramValue, namedTypes.get(paramName)));
8
4507cb9a0cf1 more exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    79
						} else { // Numbered parameters:
4507cb9a0cf1 more exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    80
							Parameter parameter;
4507cb9a0cf1 more exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    81
							if (numberedTypes.isEmpty()) {
4507cb9a0cf1 more exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    82
								parameter = new Parameter(arg, null);
4507cb9a0cf1 more exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    83
							} else {
4507cb9a0cf1 more exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    84
								int paramIndex = options.getNumberedParameters().size();
4507cb9a0cf1 more exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    85
								int paramType;
4507cb9a0cf1 more exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    86
								try {
4507cb9a0cf1 more exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    87
									paramType = numberedTypes.get(paramIndex);
4507cb9a0cf1 more exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    88
								} catch (IndexOutOfBoundsException e) {
9
2ec52027b97f better exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    89
									throw new CLIParserException("Missing type for parameter #" + paramIndex, e);
8
4507cb9a0cf1 more exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    90
								} catch (NullPointerException e) {
9
2ec52027b97f better exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
    91
									throw new CLIParserException("Invalid type definition for parameter #" + paramIndex, e);
8
4507cb9a0cf1 more exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    92
								}
4507cb9a0cf1 more exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    93
								parameter = new Parameter(arg, paramType);
4
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    94
							}
8
4507cb9a0cf1 more exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
    95
							options.addNumberedParameter(parameter);
4
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    96
						}
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
    97
					}
1
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
    98
					break;
14
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
    99
				case Tokens.FORMATTER:
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
   100
					options.setFormatterName(fetchNext(args, ++i));
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
   101
					break;
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
   102
				case Tokens.INFO_HELP:
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
   103
					options.addShowInfo(CLIOptions.INFO_TYPE.HELP);
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
   104
					break;
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
   105
				case Tokens.INFO_FORMATTERS:
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
   106
					options.addShowInfo(CLIOptions.INFO_TYPE.FORMATTERS);
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
   107
					break;
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
   108
				case Tokens.INFO_LICENSE:
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
   109
					options.addShowInfo(CLIOptions.INFO_TYPE.LICENSE);
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
   110
					break;
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
   111
				case Tokens.INFO_TYPES:
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
   112
					options.addShowInfo(CLIOptions.INFO_TYPE.TYPES);
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
   113
					break;
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
   114
				case Tokens.INFO_VERSION:
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
   115
					options.addShowInfo(CLIOptions.INFO_TYPE.VERSION);
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
   116
					break;
15
bbd335b5410c show info basics: list databases + test connection
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
   117
				case Tokens.INFO_DATABASES:
bbd335b5410c show info basics: list databases + test connection
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
   118
					options.addShowInfo(CLIOptions.INFO_TYPE.DATABASES);
bbd335b5410c show info basics: list databases + test connection
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
   119
					break;
bbd335b5410c show info basics: list databases + test connection
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
   120
				case Tokens.INFO_CONNECTION:
bbd335b5410c show info basics: list databases + test connection
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
   121
					options.addShowInfo(CLIOptions.INFO_TYPE.CONNECTION);
bbd335b5410c show info basics: list databases + test connection
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
   122
					options.setDatabaseNameToTest(fetchNext(args, ++i));
bbd335b5410c show info basics: list databases + test connection
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
   123
					break;
4
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   124
				default:
9
2ec52027b97f better exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
   125
					throw new CLIParserException("Unknown option: " + arg);
1
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   126
			}
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   127
		}
8
4507cb9a0cf1 more exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
   128
		return options;
4507cb9a0cf1 more exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
   129
	}
4
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   130
9
2ec52027b97f better exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
   131
	private String fetchNext(String[] args, int index) throws CLIParserException {
8
4507cb9a0cf1 more exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
   132
		if (index < args.length) {
4507cb9a0cf1 more exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
   133
			return args[index];
4507cb9a0cf1 more exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
   134
		} else {
9
2ec52027b97f better exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
   135
			throw new CLIParserException("Expecting value for option: " + args[index - 1]);
8
4507cb9a0cf1 more exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
   136
		}
1
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   137
	}
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   138
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   139
	public static class Tokens {
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   140
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   141
		public static final String DB = "--db";
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   142
		public static final String SQL = "--sql";
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   143
		public static final String SQL_UPDATE = "--sql-update";
2
72da10f632b5 more code
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   144
		public static final String SQL_INSERT = "--sql-insert";
1
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   145
		public static final String BATCH = "--batch";
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   146
		public static final String DATA = "--data";
2
72da10f632b5 more code
František Kučera <franta-hg@frantovo.cz>
parents: 1
diff changeset
   147
		public static final String NAME_PREFIX = "--name-prefix";
1
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   148
		public static final String TYPES = "--types";
14
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
   149
		public static final String FORMATTER = "--formatter";
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
   150
		public static final String INFO_HELP = "--help";
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
   151
		public static final String INFO_VERSION = "--version";
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
   152
		public static final String INFO_LICENSE = "--license";
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
   153
		public static final String INFO_FORMATTERS = "--list-formatters";
189b1260b942 show info basics
František Kučera <franta-hg@frantovo.cz>
parents: 12
diff changeset
   154
		public static final String INFO_TYPES = "--list-types";
15
bbd335b5410c show info basics: list databases + test connection
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
   155
		public static final String INFO_DATABASES = "--list-databases";
bbd335b5410c show info basics: list databases + test connection
František Kučera <franta-hg@frantovo.cz>
parents: 14
diff changeset
   156
		public static final String INFO_CONNECTION = "--test-connection";
1
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   157
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   158
		private Tokens() {
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   159
		}
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   160
	}
4
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   161
9
2ec52027b97f better exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
   162
	private int getType(String typeString) throws CLIParserException {
10
f528406f33f4 unit-test: types
František Kučera <franta-hg@frantovo.cz>
parents: 9
diff changeset
   163
		Integer type = types.get(typeString.trim());
8
4507cb9a0cf1 more exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
   164
		if (type == null) {
9
2ec52027b97f better exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 8
diff changeset
   165
			throw new CLIParserException("Unsupported type: " + typeString);
8
4507cb9a0cf1 more exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
   166
		} else {
4507cb9a0cf1 more exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
   167
			return type;
4507cb9a0cf1 more exceptions
František Kučera <franta-hg@frantovo.cz>
parents: 5
diff changeset
   168
		}
4
f5c3350f3d78 data/types CLI options parsing
František Kučera <franta-hg@frantovo.cz>
parents: 3
diff changeset
   169
	}
1
f32dac78d13a WOW some classes LOL; TODO: refactor
František Kučera <franta-hg@frantovo.cz>
parents:
diff changeset
   170
}