mirror of
https://github.com/Wisser/Jailer.git
synced 2026-02-22 10:18:33 -06:00
print cli arguments on error
This commit is contained in:
@@ -15,7 +15,7 @@ mv $1.co/Jailer/* jailer
|
||||
cd jailer
|
||||
|
||||
sed "s/stateOffset = 100/stateOffset = 0/g" src/main/gui/net/sf/jailer/ui/Environment.java --in-place
|
||||
ant package
|
||||
ant all
|
||||
sed "s/stateOffset = 0/stateOffset = 100/g" src/main/gui/net/sf/jailer/ui/Environment.java --in-place
|
||||
|
||||
rm -rf docs/api
|
||||
@@ -63,5 +63,4 @@ zip -r dbeauty_$1.zip dbeauty
|
||||
# Web upload
|
||||
# cd docs
|
||||
# scp -r * rwisser,jailer@web.sf.net:/home/groups/j/ja/jailer/htdocs/
|
||||
# scp -r * rwisser,jailer@web.sf.net:/home/groups/j/ja/jailer/htdocs/doc/
|
||||
|
||||
|
||||
@@ -87,7 +87,7 @@ available targets:
|
||||
</jar>
|
||||
</target>
|
||||
|
||||
<target name="package" depends="package-engine,compile-gui,javadoc">
|
||||
<target name="package" depends="package-engine,compile-gui">
|
||||
<jar destfile="${JAR}" basedir="${COMPILE_DIR}">
|
||||
<manifest>
|
||||
<attribute name="Main-Class" value="net.sf.jailer.ui.ExtractionModelFrame" />
|
||||
@@ -184,7 +184,7 @@ available targets:
|
||||
</junit>
|
||||
</target>
|
||||
|
||||
<target name="javadoc">
|
||||
<target name="all" depends="package">
|
||||
<zip destfile="${JAR-ENGINE-SRC}" basedir="${SRC_DIR}/main/engine">
|
||||
</zip>
|
||||
<javadoc packagenames="net.sf.jailer.*" sourcepath="src/main/engine" defaultexcludes="yes" destdir="docs/api" author="true" version="true" use="true" windowtitle="Jailer Subsetter API">
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package net.sf.jailer;
|
||||
|
||||
import java.io.PrintStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -65,14 +66,14 @@ public class CommandLineParser {
|
||||
commandLine.arguments = escapedWords;
|
||||
if (commandLine.arguments.isEmpty()) {
|
||||
if (!silent) {
|
||||
printUsage();
|
||||
printUsage(args);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return commandLine;
|
||||
} catch (CmdLineException e) {
|
||||
System.out.println(e.getMessage());
|
||||
printUsage();
|
||||
printUsage(args);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
@@ -80,7 +81,7 @@ public class CommandLineParser {
|
||||
/**
|
||||
* Prints out usage.
|
||||
*/
|
||||
public static void printUsage() {
|
||||
public static void printUsage(String[] args) {
|
||||
System.out.println("usage:");
|
||||
System.out.println(" jailer export [options] <extraction-model> <jdbc-driver-class> <db-URL> <db-user> <db-password>");
|
||||
System.out.println(" extracts data (see option '-e') and optionally creates a delete-script (see option '-d')");
|
||||
@@ -126,6 +127,28 @@ public class CommandLineParser {
|
||||
cmdLineParser.setUsageWidth(120);
|
||||
cmdLineParser.printUsage(System.out);
|
||||
System.out.println();
|
||||
printAruments(System.out, args, null);
|
||||
}
|
||||
|
||||
public static void printAruments(PrintStream out, String[] args, String password) {
|
||||
if (args.length > 0) {
|
||||
out.println();
|
||||
out.print("Arguments: ");
|
||||
int i = 0;
|
||||
while (i < args.length) {
|
||||
String arg = args[i];
|
||||
if (arg.equals(password)) {
|
||||
arg = "?";
|
||||
}
|
||||
if (i > 0) {
|
||||
out.print(", ");
|
||||
}
|
||||
out.print(" " + i + ": {" + arg + "}");
|
||||
++i;
|
||||
}
|
||||
out.println();
|
||||
out.println();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -146,6 +146,7 @@ public class Jailer {
|
||||
*/
|
||||
public static boolean jailerMain(String[] args, StringBuffer warnings, ProgressListener progressListener, boolean fromCli) throws Exception {
|
||||
CancellationHandler.reset(null);
|
||||
String pw = null;
|
||||
|
||||
try {
|
||||
CommandLine commandLine = CommandLineParser.parse(args, false);
|
||||
@@ -169,16 +170,16 @@ public class Jailer {
|
||||
|
||||
if ("render-datamodel".equalsIgnoreCase(command)) {
|
||||
if (commandLine.arguments.size() <= 1) {
|
||||
CommandLineParser.printUsage();
|
||||
CommandLineParser.printUsage(args);
|
||||
} else {
|
||||
renderDataModel(commandLine.arguments, commandLine.withClosures, commandLine.schema, executionContext);
|
||||
}
|
||||
} else if ("import".equalsIgnoreCase(command)) {
|
||||
if (commandLine.arguments.size() != 6) {
|
||||
CommandLineParser.printUsage();
|
||||
CommandLineParser.printUsage(args);
|
||||
} else {
|
||||
BasicDataSource dataSource = new BasicDataSource(commandLine.arguments.get(2), commandLine.arguments.get(3), commandLine.arguments.get(4),
|
||||
commandLine.arguments.get(5), 0, jdbcJarURLs);
|
||||
pw = commandLine.arguments.get(5), 0, jdbcJarURLs);
|
||||
Session session = new Session(dataSource, dataSource.dbms, commandLine.isolationLevel, null, commandLine.transactional);
|
||||
try {
|
||||
new SqlScriptExecutor(session, commandLine.numberOfThreads, false).executeScript(commandLine.arguments.get(1), commandLine.transactional);
|
||||
@@ -194,8 +195,9 @@ public class Jailer {
|
||||
printDataModel(commandLine.arguments, commandLine.withClosures, executionContext);
|
||||
} else if ("export".equalsIgnoreCase(command)) {
|
||||
if (commandLine.arguments.size() != 6) {
|
||||
CommandLineParser.printUsage();
|
||||
CommandLineParser.printUsage(args);
|
||||
} else {
|
||||
pw = commandLine.arguments.get(5);
|
||||
if (commandLine.maxNumberOfEntities > 0) {
|
||||
EntityGraph.maxTotalRowcount = commandLine.maxNumberOfEntities;
|
||||
_log.info("max-rowcount=" + EntityGraph.maxTotalRowcount);
|
||||
@@ -203,7 +205,7 @@ public class Jailer {
|
||||
|
||||
if (commandLine.exportScriptFileName == null) {
|
||||
System.out.println("missing '-e' option");
|
||||
CommandLineParser.printUsage();
|
||||
CommandLineParser.printUsage(args);
|
||||
} else {
|
||||
if (!commandLine.independentWorkingTables) {
|
||||
PrimaryKeyFactory.createUPKScope(commandLine.arguments.get(1), executionContext);
|
||||
@@ -218,11 +220,12 @@ public class Jailer {
|
||||
}
|
||||
} else if ("delete".equalsIgnoreCase(command)) {
|
||||
if (commandLine.arguments.size() != 6) {
|
||||
CommandLineParser.printUsage();
|
||||
CommandLineParser.printUsage(args);
|
||||
} else {
|
||||
pw = commandLine.arguments.get(5);
|
||||
if (commandLine.deleteScriptFileName == null) {
|
||||
System.out.println("missing '-d' option");
|
||||
CommandLineParser.printUsage();
|
||||
CommandLineParser.printUsage(args);
|
||||
} else {
|
||||
BasicDataSource dataSource = new BasicDataSource(commandLine.arguments.get(2), commandLine.arguments.get(3),
|
||||
commandLine.arguments.get(4), commandLine.arguments.get(5), 0, jdbcJarURLs);
|
||||
@@ -238,7 +241,7 @@ public class Jailer {
|
||||
}
|
||||
} else if ("find-association".equalsIgnoreCase(command)) {
|
||||
if (commandLine.arguments.size() < 3) {
|
||||
CommandLineParser.printUsage();
|
||||
CommandLineParser.printUsage(args);
|
||||
} else {
|
||||
findAssociation(commandLine.arguments.get(1), commandLine.arguments.get(2), commandLine.arguments.subList(3, commandLine.arguments.size()), commandLine.undirected, executionContext);
|
||||
}
|
||||
@@ -257,6 +260,7 @@ public class Jailer {
|
||||
}
|
||||
}
|
||||
if (commandLine.arguments.size() >= 5) {
|
||||
pw = commandLine.arguments.get(4);
|
||||
if (!commandLine.independentWorkingTables && commandLine.arguments.size() > 5) {
|
||||
PrimaryKeyFactory.createUPKScope(extractionModelFileName, executionContext);
|
||||
}
|
||||
@@ -280,22 +284,24 @@ public class Jailer {
|
||||
return new DDLCreator(executionContext).createDDL((DataSource) null, null, executionContext.getScope(), commandLine.workingTableSchema);
|
||||
} else if ("build-model-wo-merge".equalsIgnoreCase(command)) {
|
||||
if (commandLine.arguments.size() != 5) {
|
||||
CommandLineParser.printUsage();
|
||||
CommandLineParser.printUsage(args);
|
||||
} else {
|
||||
pw = commandLine.arguments.get(4);
|
||||
_log.info("Building data model.");
|
||||
BasicDataSource dataSource = new BasicDataSource(commandLine.arguments.get(1), commandLine.arguments.get(2), commandLine.arguments.get(3), commandLine.arguments.get(4), 0, jdbcJarURLs);
|
||||
ModelBuilder.build(dataSource, dataSource.dbms, commandLine.schema, warnings, executionContext);
|
||||
}
|
||||
} else if ("build-model".equalsIgnoreCase(command)) {
|
||||
if (commandLine.arguments.size() != 5) {
|
||||
CommandLineParser.printUsage();
|
||||
CommandLineParser.printUsage(args);
|
||||
} else {
|
||||
pw = commandLine.arguments.get(4);
|
||||
_log.info("Building data model.");
|
||||
BasicDataSource dataSource = new BasicDataSource(commandLine.arguments.get(1), commandLine.arguments.get(2), commandLine.arguments.get(3), commandLine.arguments.get(4), 0, jdbcJarURLs);
|
||||
ModelBuilder.buildAndMerge(dataSource, dataSource.dbms, commandLine.schema, warnings, executionContext);
|
||||
}
|
||||
} else {
|
||||
CommandLineParser.printUsage();
|
||||
CommandLineParser.printUsage(args);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@@ -305,7 +311,8 @@ public class Jailer {
|
||||
throw e;
|
||||
}
|
||||
_log.error(e.getMessage(), e);
|
||||
System.out.println("Error: " + e.getClass().getName() + ": " + e.getMessage());
|
||||
System.err.println("Error: " + e.getClass().getName() + ": " + e.getMessage());
|
||||
CommandLineParser.printAruments(System.err, args, pw);
|
||||
String workingDirectory = System.getProperty("user.dir");
|
||||
_log.error("working directory is " + workingDirectory);
|
||||
throw e;
|
||||
|
||||
@@ -640,10 +640,11 @@ public class UIUtil {
|
||||
break;
|
||||
}
|
||||
}
|
||||
char q = System.getProperty("os.name", "").toLowerCase().startsWith("windows") ? '"' : '\'';
|
||||
for (int i = 0; i < args.size(); ++i) {
|
||||
String arg = args.get(i);
|
||||
if (i == pwi) {
|
||||
arglist.append((escMinus? " -" : "") + " \"<password>\"");
|
||||
arglist.append((escMinus? " -" : "") + " " + q + "<password>" + q);
|
||||
} else {
|
||||
if (escMinus && arg.startsWith("-") && user != null && arg.equals(user)) {
|
||||
arglist.append(" -");
|
||||
@@ -651,15 +652,15 @@ public class UIUtil {
|
||||
if ("".equals(arg) || arg.contains(" ") || arg.contains("<") || arg.contains(">") || arg.contains("*")
|
||||
|| arg.contains("?") || arg.contains("|") || arg.contains("$") || arg.contains("\"")
|
||||
|| arg.contains("'") || arg.contains("\\") || arg.contains(";") || arg.contains("&")) {
|
||||
arglist.append(" \"");
|
||||
arglist.append(" " + q);
|
||||
for (int j = 0; j < arg.length(); ++j) {
|
||||
char c = arg.charAt(j);
|
||||
if (c == '\"' || c == '$') {
|
||||
if (c == '\"' || c == '\'' || c == '$') {
|
||||
arglist.append("\\");
|
||||
}
|
||||
arglist.append(c);
|
||||
}
|
||||
arglist.append("\"");
|
||||
arglist.append(q);
|
||||
} else {
|
||||
arglist.append(" " + arg);
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ import java.util.List;
|
||||
|
||||
import org.kohsuke.args4j.CmdLineParser;
|
||||
|
||||
import net.sf.jailer.ui.UIUtil;
|
||||
|
||||
/**
|
||||
* Parser for {@link UICommandLine}.
|
||||
*
|
||||
@@ -39,6 +41,7 @@ public class UICommandLineParser {
|
||||
UICommandLine commandLine = new UICommandLine();
|
||||
try {
|
||||
List<String> theArgs = new ArrayList<String>();
|
||||
StringBuilder allArgs = new StringBuilder(UIUtil.LINE_SEPARATOR + "Arguments: ");
|
||||
|
||||
final String ESC_PREFIX = "((!JAILER_MINUS_ESC!!)";
|
||||
|
||||
@@ -52,6 +55,18 @@ public class UICommandLineParser {
|
||||
}
|
||||
++i;
|
||||
}
|
||||
if (args.length > 0) {
|
||||
i = 0;
|
||||
while (i < args.length) {
|
||||
String arg = args[i];
|
||||
if (i > 0) {
|
||||
allArgs.append(", ");
|
||||
}
|
||||
allArgs.append(" " + i + ": {" + arg + "}");
|
||||
++i;
|
||||
}
|
||||
allArgs.append(UIUtil.LINE_SEPARATOR);
|
||||
}
|
||||
|
||||
CmdLineParser cmdLineParser = new CmdLineParser(commandLine);
|
||||
cmdLineParser.parseArgument(theArgs.toArray(new String[0]));
|
||||
@@ -65,10 +80,10 @@ public class UICommandLineParser {
|
||||
}
|
||||
commandLine.arguments = escapedWords;
|
||||
if (commandLine.arguments.size() > 1) {
|
||||
throw new RuntimeException("Illegal arguments " + commandLine.arguments);
|
||||
throw new RuntimeException("Illegal arguments " + commandLine.arguments + allArgs);
|
||||
}
|
||||
if (commandLine.arguments.size() == 1 && !commandLine.arguments.get(0).toLowerCase().endsWith(".jm")) {
|
||||
throw new RuntimeException("'" + commandLine.arguments.get(0) + "' is not a valid extraction model file.");
|
||||
throw new RuntimeException("'" + commandLine.arguments.get(0) + "' is not a valid extraction model file." + allArgs);
|
||||
}
|
||||
if (commandLine.datamodelFolder == null && commandLine.arguments.isEmpty()) {
|
||||
commandLine.url = null;
|
||||
|
||||
Reference in New Issue
Block a user