Browse files

Merge branch 'logging_switch'

  • Loading branch information...
2 parents 3766d3b + 7d67e91 commit 9698754cfc8cef8ea87421256697305ff2001be5 @dclements committed Feb 28, 2012
View
23 src/main/java/com/readytalk/staccato/CommandLineServiceImpl.java
@@ -1,11 +1,10 @@
package com.readytalk.staccato;
-import java.util.IllegalFormatException;
-
import org.apache.commons.cli.CommandLine;
import org.apache.commons.cli.CommandLineParser;
import org.apache.commons.cli.HelpFormatter;
import org.apache.commons.cli.Option;
+import org.apache.commons.cli.OptionBuilder;
import org.apache.commons.cli.Options;
import org.apache.commons.cli.ParseException;
@@ -32,7 +31,15 @@ private void init() {
StaccatoOptions.Arg[] staccatoArgs = StaccatoOptions.Arg.values();
for (StaccatoOptions.Arg staccatoArg : staccatoArgs) {
- Option opt = new Option(staccatoArg.getOpt(), staccatoArg.getLongOpt(), true, staccatoArg.getDesc());
+
+ @SuppressWarnings("static-access")
+ Option opt = OptionBuilder.withArgName(staccatoArg.getOpt())
+ .withLongOpt(staccatoArg.getLongOpt())
+ .hasArg(staccatoArg.isArgOption())
+ .withDescription(staccatoArg.getDesc())
+ .isRequired(staccatoArg.isRequired()).create(staccatoArg.getOpt());
+
+ new Option(staccatoArg.getOpt(), staccatoArg.getLongOpt(), true, staccatoArg.getDesc());
opt.setRequired(staccatoArg.isRequired());
options.addOption(opt);
}
@@ -64,7 +71,6 @@ public StaccatoOptions parse(final String... args) {
String migrateToVer = cli.getOptionValue(StaccatoOptions.Arg.MIGRATE_TO_VER.getOpt());
String rootDb = cli.getOptionValue(StaccatoOptions.Arg.ROOT_DB.getOpt());
String migrationJarPath = cli.getOptionValue(StaccatoOptions.Arg.MIGRATION_JAR_PATH.getOpt());
- String logging = cli.getOptionValue(StaccatoOptions.Arg.LOGGING.getOpt());
StaccatoOptions staccatoOptions = new StaccatoOptions();
staccatoOptions.jdbcUrl = jdbcUrl;
@@ -82,14 +88,7 @@ public StaccatoOptions parse(final String... args) {
staccatoOptions.migrateToVer = migrateToVer;
staccatoOptions.rootDb = rootDb;
staccatoOptions.migrationJarPath = migrationJarPath;
-
- //TODO: Check exception path.
- try {
- final Boolean loggingEnabled = Boolean.valueOf(logging);
- staccatoOptions.enableLogging = loggingEnabled;
- } catch (final IllegalFormatException ife) {
- staccatoOptions.enableLogging = true;
- }
+ staccatoOptions.enableLogging = cli.hasOption(StaccatoOptions.Arg.LOGGING.getOpt());
return staccatoOptions;
} catch (ParseException e) {
View
29 src/main/java/com/readytalk/staccato/StaccatoOptions.java
@@ -51,7 +51,7 @@
@Version(strictMode = Migration.databaseVersionStrictMode)
public String migrateToVer;
- public boolean enableLogging = true;
+ public boolean enableLogging = false;
public static enum Arg {
JDBC_URL("j", "jdbc", "The JDBC URL. This url should not contain the database name. Please provide the database name via the 'n' option.", true),
@@ -75,18 +75,25 @@
MIGRATION_JAR_PATH("mj", "migrationJar", "The path to the migration jar", false),
LOGGING("l", "logging", "Toggles the migration logging system, which logs script " +
"execution to the 'staccato_migrations' table in the database. Set to 'false' if you don't " +
- "want Staccato to create a 'staccato_migrations' table in your database. Defaults to 'true' if anything other than 'false' is specified.", false);
-
- private String opt;
- private String longOpt;
- private String desc;
- private boolean required;
-
- Arg(final String _opt, final String _longOpt, final String _desc, final boolean _required) {
+ "want Staccato to create a 'staccato_migrations' table in your database. Defaults to 'true' if anything other than 'false' is specified.", false, false);
+
+ private final String opt;
+ private final String longOpt;
+ private final String desc;
+ private final boolean required;
+ private final boolean hasArg;
+
+
+ private Arg(final String _opt, final String _longOpt, final String _desc, final boolean _required, boolean _hasArg) {
this.opt = _opt;
this.longOpt = _longOpt;
this.desc = _desc;
this.required = _required;
+ this.hasArg = _hasArg;
+ }
+
+ private Arg(final String _opt, final String _longOpt, final String _desc, final boolean _required) {
+ this(_opt, _longOpt, _desc, _required, true);
}
public String getOpt() {
@@ -104,5 +111,9 @@ public String getLongOpt() {
public boolean isRequired() {
return required;
}
+
+ public boolean isArgOption() {
+ return hasArg;
+ }
}
}
View
8 src/test/true_unit/com/readytalk/staccato/CommandLineServiceTest.java
@@ -80,7 +80,7 @@ public void testAllRequiredParse() throws Exception {
"--dbUser", "staccato2",
"--dbPwd", "staccato3",
"--migration", "migration",
- "--logging", "true"
+ "--logging"
};
final StaccatoOptions so = service.parse(args);
@@ -97,7 +97,7 @@ public void testAllRequiredShortParse() throws Exception {
"-u", "staccato2",
"-p", "staccato3",
"-m", "migration",
- "-l", "true"
+ "-l"
};
final StaccatoOptions so = service.parse(args);
@@ -110,7 +110,7 @@ public void testAllRequiredShortParse() throws Exception {
public void testAllShortParse() throws Exception {
String[] args = new String[]{"-j", "jdbcUri", "-n", "dbName", "-u", "dbUser", "-p", "staccato3",
"-m", "UP", "fd", "fromDate", "td", "toDate", "-s", "test.groovy", "-d", "migrations/",
- "rn", "rootDbName", "-su", "superuser", "-sup", "superuserPwd", "-fv", "fromVer", "-tv", "toVer", "-l", "true"};
+ "rn", "rootDbName", "-su", "superuser", "-sup", "superuserPwd", "-fv", "fromVer", "-tv", "toVer", "-l"};
final StaccatoOptions so = service.parse(args);
verify(parser).parse(any(Options.class), eq(args));
@@ -123,7 +123,7 @@ public void testAllLongParse() throws Exception {
String[] args = new String[]{"-jdbc", "jdbcUri", "-dbName", "dbName", "-dbUser", "dbUser", "-dbPwd", "staccato3",
"-migration", "UP", "fromDate", "fromDate", "toDate", "toDate", "-script", "test.groovy", "-directory", "migrations/",
"rootDbName", "rootDbName", "-dbSuperUser", "superuser", "-dbSuperPwd", "superuserPwd", "-fromVersion", "fromVer", "-tv", "toVersion",
- "-logging", "true"};
+ "-logging"};
final StaccatoOptions so = service.parse(args);

0 comments on commit 9698754

Please sign in to comment.