32 import java.util.Set; |
32 import java.util.Set; |
33 import java.util.regex.Pattern; |
33 import java.util.regex.Pattern; |
34 import java.util.regex.PatternSyntaxException; |
34 import java.util.regex.PatternSyntaxException; |
35 |
35 |
36 /** |
36 /** |
|
37 * Holds options from command line, validates them, combines with configuration and provides derived |
|
38 * objects. |
37 * |
39 * |
38 * @author Ing. František Kučera (frantovo.cz) |
40 * @author Ing. František Kučera (frantovo.cz) |
39 */ |
41 */ |
40 public class CLIOptions { |
42 public class CLIOptions { |
41 |
43 |
42 public static final String DEFAULT_NAME_PREFIX = ":"; |
44 public static final String DEFAULT_NAME_PREFIX = ":"; |
43 public static final String DEFAULT_NAME_SUFFIX = "(?=([^\\w]|$))"; |
45 public static final String DEFAULT_NAME_SUFFIX = "(?=([^\\w]|$))"; |
44 private String sql; |
46 private String sql; |
45 private String databaseName; |
47 private String databaseName; |
46 private Set<String> databaseNameToTest = new HashSet<>(); |
48 private Set<String> databaseNamesToTest = new HashSet<>(); |
47 private String namePrefix = DEFAULT_NAME_PREFIX; |
49 private String namePrefix = DEFAULT_NAME_PREFIX; |
48 private String nameSuffix = DEFAULT_NAME_SUFFIX; |
50 private String nameSuffix = DEFAULT_NAME_SUFFIX; |
49 private String formatterName; |
51 private String formatterName; |
50 private boolean batch; |
52 private boolean batch; |
51 private Properties formatterProperties = new Properties(); |
53 private Properties formatterProperties = new Properties(); |
88 e.addProblem(new InvalidOptionsException.OptionProblem("Do not specify name prefix if just showing info.")); |
90 e.addProblem(new InvalidOptionsException.OptionProblem("Do not specify name prefix if just showing info.")); |
89 } |
91 } |
90 if (!equalz(nameSuffix, DEFAULT_NAME_SUFFIX)) { |
92 if (!equalz(nameSuffix, DEFAULT_NAME_SUFFIX)) { |
91 e.addProblem(new InvalidOptionsException.OptionProblem("Do not specify name suffix if just showing info.")); |
93 e.addProblem(new InvalidOptionsException.OptionProblem("Do not specify name suffix if just showing info.")); |
92 } |
94 } |
93 if (showInfo.contains(InfoType.CONNECTION) && databaseNameToTest.isEmpty()) { |
95 if (showInfo.contains(InfoType.CONNECTION) && databaseNamesToTest.isEmpty()) { |
94 e.addProblem(new InvalidOptionsException.OptionProblem("Please specify which database should be tested.")); |
96 e.addProblem(new InvalidOptionsException.OptionProblem("Please specify which database should be tested.")); |
95 } |
97 } |
96 } |
98 } |
97 |
99 |
98 if (!namedParameters.isEmpty() && !numberedParameters.isEmpty()) { |
100 if (!namedParameters.isEmpty() && !numberedParameters.isEmpty()) { |
230 |
232 |
231 public EnumSet<InfoType> getShowInfo() { |
233 public EnumSet<InfoType> getShowInfo() { |
232 return showInfo; |
234 return showInfo; |
233 } |
235 } |
234 |
236 |
235 public Set<String> getDatabaseNameToTest() { |
237 public Set<String> getDatabaseNamesToTest() { |
236 return databaseNameToTest; |
238 return databaseNamesToTest; |
237 } |
239 } |
238 |
240 |
239 public void addDatabaseNameToTest(String databaseNameToTest) { |
241 public void addDatabaseNamesToTest(String databaseNameToTest) { |
240 this.databaseNameToTest.add(databaseNameToTest); |
242 this.databaseNamesToTest.add(databaseNameToTest); |
241 } |
243 } |
242 |
244 |
243 public SQLCommand getSQLCommand() { |
245 public SQLCommand getSQLCommand() { |
244 if (namedParameters.isEmpty()) { |
246 if (namedParameters.isEmpty()) { |
245 return new SQLCommandNumbered(sql, numberedParameters); |
247 return new SQLCommandNumbered(sql, numberedParameters); |