Skip to content

Commit 3b5357d

Browse files
committed
[bugfix] Add missing CLI --help arguments
1 parent 3c947f3 commit 3b5357d

File tree

5 files changed

+70
-1
lines changed

5 files changed

+70
-1
lines changed

exist-core/src/main/java/org/exist/backup/ExportGUI.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@
3333
import org.exist.util.MimeType;
3434
import org.exist.util.SystemExitCodes;
3535
import org.exist.xquery.TerminatedException;
36+
import se.softhouse.jargo.Argument;
37+
import se.softhouse.jargo.ArgumentException;
38+
import se.softhouse.jargo.CommandLineParser;
3639

3740
import javax.swing.*;
3841
import javax.swing.filechooser.FileFilter;
@@ -48,6 +51,7 @@
4851
import static java.nio.charset.StandardCharsets.UTF_8;
4952
import static org.exist.util.ThreadUtils.newGlobalThread;
5053
import static org.exist.util.ThreadUtils.newInstanceThread;
54+
import static se.softhouse.jargo.Arguments.helpArgument;
5155

5256

5357
/**
@@ -58,6 +62,9 @@
5862
public class ExportGUI extends javax.swing.JFrame {
5963
private static final long serialVersionUID = -8104424554660744639L;
6064

65+
/* general arguments */
66+
private static final Argument<?> helpArg = helpArgument("-h", "--help");
67+
6168
private BrokerPool pool = null;
6269
private int documentCount = 0;
6370
private PrintWriter logWriter = null;
@@ -613,13 +620,26 @@ private void closeLog() {
613620
public static void main(final String[] args) {
614621
try {
615622
CompatibleJavaVersionCheck.checkForCompatibleJavaVersion();
623+
624+
// parse command-line options
625+
CommandLineParser
626+
.withArguments(helpArg)
627+
.parse(args);
628+
616629
} catch (final StartException e) {
617630
if (e.getMessage() != null && !e.getMessage().isEmpty()) {
618631
System.err.println(e.getMessage());
619632
}
620633
System.exit(e.getErrorCode());
634+
} catch (final ArgumentException e) {
635+
consoleOut(e.getMessageAndUsage().toString());
636+
System.exit(SystemExitCodes.INVALID_ARGUMENT_EXIT_CODE);
621637
}
622638

623639
java.awt.EventQueue.invokeLater(() -> new ExportGUI().setVisible(true));
624640
}
641+
642+
private static void consoleOut(final String msg) {
643+
System.out.println(msg); //NOSONAR this has to go to the console
644+
}
625645
}

exist-core/src/main/java/org/exist/jetty/JettyStart.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,15 @@
4444
import org.exist.util.ConfigurationHelper;
4545
import org.exist.util.FileUtils;
4646
import org.exist.util.SingleInstanceConfiguration;
47+
import org.exist.util.SystemExitCodes;
4748
import org.exist.validation.XmlLibraryChecker;
4849
import org.exist.xmldb.DatabaseImpl;
4950
import org.exist.xmldb.ShutdownListener;
5051
import org.xmldb.api.DatabaseManager;
5152
import org.xmldb.api.base.Database;
53+
import se.softhouse.jargo.Argument;
54+
import se.softhouse.jargo.ArgumentException;
55+
import se.softhouse.jargo.CommandLineParser;
5256

5357
import java.io.IOException;
5458
import java.io.LineNumberReader;
@@ -61,6 +65,7 @@
6165
import java.util.stream.Collectors;
6266

6367
import static org.exist.util.ThreadUtils.newGlobalThread;
68+
import static se.softhouse.jargo.Arguments.helpArgument;
6469

6570
/**
6671
* This class provides a main method to start Jetty with eXist. It registers shutdown
@@ -85,19 +90,32 @@ public class JettyStart extends Observable implements LifeCycle.Listener {
8590
private final static int STATUS_STOPPING = 2;
8691
private final static int STATUS_STOPPED = 3;
8792

93+
/* general arguments */
94+
private static final Argument<?> helpArg = helpArgument("-h", "--help");
95+
8896
@GuardedBy("this") private int status = STATUS_STOPPED;
8997
@GuardedBy("this") private Optional<Thread> shutdownHookThread = Optional.empty();
9098
@GuardedBy("this") private int primaryPort = 8080;
9199

92100

93101
public static void main(final String[] args) {
102+
String jettyConfigFile = null;
103+
Optional<String> existdbConfigFile = Optional.empty();
94104
try {
95105
CompatibleJavaVersionCheck.checkForCompatibleJavaVersion();
106+
107+
CommandLineParser
108+
.withArguments(helpArg)
109+
.parse(args);
110+
96111
} catch (final StartException e) {
97112
if (e.getMessage() != null && !e.getMessage().isEmpty()) {
98113
System.err.println(e.getMessage());
99114
}
100115
System.exit(e.getErrorCode());
116+
} catch (final ArgumentException e) {
117+
consoleOut(e.getMessageAndUsage().toString());
118+
System.exit(SystemExitCodes.INVALID_ARGUMENT_EXIT_CODE);
101119
}
102120

103121
final JettyStart start = new JettyStart();
@@ -109,6 +127,10 @@ public JettyStart() {
109127
XmlLibraryChecker.check();
110128
}
111129

130+
private static void consoleOut(final String msg) {
131+
System.out.println(msg); //NOSONAR this has to go to the console
132+
}
133+
112134
public synchronized void run() {
113135
run(true);
114136
}

exist-core/src/main/java/org/exist/launcher/LauncherWrapper.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@
2424
import org.exist.start.CompatibleJavaVersionCheck;
2525
import org.exist.start.StartException;
2626
import org.exist.util.ConfigurationHelper;
27+
import org.exist.util.SystemExitCodes;
28+
import se.softhouse.jargo.Argument;
29+
import se.softhouse.jargo.ArgumentException;
30+
import se.softhouse.jargo.CommandLineParser;
2731

2832
import javax.swing.*;
2933
import java.io.File;
@@ -37,6 +41,7 @@
3741

3842
import static java.nio.charset.StandardCharsets.UTF_8;
3943
import static org.exist.launcher.ConfigurationUtility.*;
44+
import static se.softhouse.jargo.Arguments.helpArgument;
4045

4146
/**
4247
* A wrapper to start a Java process using start.jar with correct VM settings.
@@ -51,14 +56,26 @@ public class LauncherWrapper {
5156
private final static String LAUNCHER = org.exist.launcher.Launcher.class.getName();
5257
private final static String OS = System.getProperty("os.name").toLowerCase();
5358

59+
/* general arguments */
60+
private static final Argument<?> helpArg = helpArgument("-h", "--help");
61+
5462
public final static void main(final String[] args) {
5563
try {
5664
CompatibleJavaVersionCheck.checkForCompatibleJavaVersion();
65+
66+
// parse command-line options
67+
CommandLineParser
68+
.withArguments(helpArg)
69+
.parse(args);
70+
5771
} catch (final StartException e) {
5872
if (e.getMessage() != null && !e.getMessage().isEmpty()) {
5973
System.err.println(e.getMessage());
6074
}
6175
System.exit(e.getErrorCode());
76+
} catch (final ArgumentException e) {
77+
consoleOut(e.getMessageAndUsage().toString());
78+
System.exit(SystemExitCodes.INVALID_ARGUMENT_EXIT_CODE);
6279
}
6380

6481
final LauncherWrapper wrapper = new LauncherWrapper(LAUNCHER);
@@ -203,4 +220,8 @@ protected void getLauncherOpts(final List<String> args, final Properties launche
203220
}
204221
}
205222
}
223+
224+
private static void consoleOut(final String msg) {
225+
System.out.println(msg); //NOSONAR this has to go to the console
226+
}
206227
}

exist-distribution/pom.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -871,7 +871,9 @@
871871
<daemon>
872872
<id>launcher</id>
873873
<mainClass>org.exist.start.Main</mainClass>
874-
<!-- No arguments needed! Default is to start the launcher -->
874+
<commandLineArguments>
875+
<commandLineArgument>launcher</commandLineArgument>
876+
</commandLineArguments>
875877
<platforms>
876878
<platform>booter-unix</platform>
877879
<platform>booter-windows</platform>

exist-start/src/main/java/org/exist/start/Main.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,10 @@ public void runEx(String[] args) throws StartException {
189189
_classname = "org.exist.launcher.LauncherWrapper";
190190
_mode = "jetty";
191191

192+
} else if ("launcher".equals(args[0])) {
193+
_classname = "org.exist.launcher.LauncherWrapper";
194+
_mode = "other";
195+
192196
} else if ("shutdown".equals(args[0])) {
193197
_classname = "org.exist.jetty.ServerShutdown";
194198
_mode = "other";

0 commit comments

Comments
 (0)