Skip to content

Commit 1ff0e42

Browse files
authored
add output-dir flag (#138)
1 parent 9189ce3 commit 1ff0e42

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

dumper/app/src/main/java/com/google/edwmigration/dumper/application/dumper/ConnectorArguments.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
import com.google.common.base.Predicates;
2121
import com.google.common.base.Strings;
2222
import com.google.common.collect.ComparisonChain;
23+
import com.google.edwmigration.dumper.application.dumper.annotations.RespectsInput;
24+
import com.google.edwmigration.dumper.application.dumper.connector.Connector;
25+
import com.google.edwmigration.dumper.application.dumper.connector.ConnectorProperty;
26+
import com.google.edwmigration.dumper.plugin.ext.jdk.annotation.Description;
2327
import java.io.Console;
2428
import java.io.File;
2529
import java.io.IOException;
@@ -54,10 +58,6 @@
5458
import joptsimple.ValueConverter;
5559
import org.apache.commons.lang3.BooleanUtils;
5660
import org.apache.commons.lang3.StringUtils;
57-
import com.google.edwmigration.dumper.application.dumper.annotations.RespectsInput;
58-
import com.google.edwmigration.dumper.application.dumper.connector.Connector;
59-
import com.google.edwmigration.dumper.application.dumper.connector.ConnectorProperty;
60-
import com.google.edwmigration.dumper.plugin.ext.jdk.annotation.Description;
6161
import org.slf4j.Logger;
6262
import org.slf4j.LoggerFactory;
6363
import org.springframework.core.annotation.AnnotationUtils;
@@ -138,7 +138,8 @@ public class ConnectorArguments extends DefaultArguments {
138138
private final OptionSpec<String> optionOracleSID = parser.accepts(OPT_ORACLE_SID, "SID name for oracle").withRequiredArg().describedAs("orcl").ofType(String.class);
139139
private final OptionSpec<String> optionConfiguration = parser.accepts("config", "Configuration for DB connector").withRequiredArg().ofType(String.class).withValuesSeparatedBy(';').describedAs("key=val;key1=val1");
140140
// private final OptionSpec<String> optionDatabase = parser.accepts("database", "database (can be repeated; all if not specified)").withRequiredArg().describedAs("my_dbname").withValuesSeparatedBy(',');
141-
private final OptionSpec<File> optionOutput = parser.accepts("output", "Output file").withRequiredArg().ofType(File.class).describedAs("cw-dump.zip");
141+
private final OptionSpec<File> optionOutput = parser.accepts("output", "Output file (cannot be used together with --output-dir)").withRequiredArg().ofType(File.class).describedAs("cw-dump.zip");
142+
private final OptionSpec<String> optionOutputDir = parser.accepts("output-dir", "Output directory where the zip file with the default filename should be created (cannot be used together with --output option). If you want to specify the filename, use --output option instead.").withRequiredArg().ofType(String.class).defaultsTo("").describedAs("/home/user/my-dump-dir");
142143
private final OptionSpec<Void> optionOutputContinue = parser.accepts("continue", "Continues writing a previous output file.");
143144
// TODO: Make this be an ISO instant.
144145
@Deprecated
@@ -466,6 +467,11 @@ public File getOutputFile() {
466467
return getOptions().valueOf(optionOutput);
467468
}
468469

470+
@CheckForNull
471+
public String getOutputDirectory() {
472+
return getOptions().valueOf(optionOutputDir);
473+
}
474+
469475
public boolean isOutputContinue() {
470476
return getOptions().has(optionOutputContinue);
471477
}
@@ -627,6 +633,7 @@ public String toString() {
627633
.add("user", getUser())
628634
.add("configuration", getConfiguration())
629635
.add("output", getOutputFile())
636+
.add("output-dir", getOutputDirectory())
630637
.add("query-log-earliest-timestamp", getQueryLogEarliestTimestamp())
631638
.add("query-log-days", getQueryLogDays())
632639
.add("query-log-start", getQueryLogStart())

dumper/app/src/main/java/com/google/edwmigration/dumper/application/dumper/MetadataDumper.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,21 @@ protected void run(@Nonnull Connector connector, @Nonnull ConnectorArguments arg
194194
// We had a customer request to base it on the database, but that isn't well-defined,
195195
// as there may be 0 or N databases in a single file.
196196
File outputFile = arguments.getOutputFile();
197+
String outputDirectory = arguments.getOutputDirectory();
198+
199+
boolean isDefaultPath = "".equals(outputDirectory);
200+
if (!isDefaultPath && outputFile != null) {
201+
System.out.println(
202+
"**********************************************************\n"
203+
+ "* ERROR: Using both --output and --output-dir flags is not allowed.\n"
204+
+ "* Please use --help for more information.\n"
205+
+ "**********************************************************"
206+
);
207+
return;
208+
}
209+
197210
if (outputFile == null) {
198-
outputFile = new File(connector.getDefaultFileName(arguments.isAssessment()));
211+
outputFile = new File(outputDirectory, connector.getDefaultFileName(arguments.isAssessment()));
199212
}
200213
if (arguments.isDryRun()) {
201214
String title = "Dry run: Printing task list for " + connector.getName();

0 commit comments

Comments
 (0)