33 * SPDX-License-Identifier: LGPL-2.1-only
44 */
55package net .minecraftforge .installer ;
6+ import java .awt .HeadlessException ;
67import java .io .BufferedOutputStream ;
78import java .io .File ;
89import java .io .FileNotFoundException ;
@@ -122,8 +123,8 @@ public static void main(String[] args) throws IOException, URISyntaxException {
122123
123124 try {
124125 if (!badCerts .isEmpty ()) {
125- monitor .message ("Failed to validate certificates for " + badCerts + " this typically means you have an outdated java ." );
126- monitor .message ("If instalation fails try updating your java !" );
126+ monitor .message ("Failed to validate certificates for " + badCerts + " - this typically means you have an outdated Java ." );
127+ monitor .message ("If installation fails, try updating your Java !" );
127128 return ;
128129 }
129130
@@ -151,7 +152,7 @@ public static void main(String[] args) throws IOException, URISyntaxException {
151152 }
152153
153154 if (!didWork )
154- launchGui (monitor , installer , badCerts );
155+ launchGui (monitor , installer , badCerts , parser );
155156 }
156157
157158 private static OptionSpec <File > action (OptionParser parser , String arg , String desc ) {
@@ -169,10 +170,29 @@ else if (osType.contains("mac"))
169170 return new File (userHomeDir , mcDir );
170171 }
171172
173+ // Bouncer method, just in case
172174 private static void launchGui (ProgressCallback monitor , File installer , String badCerts ) {
175+ launchGui (monitor , installer , badCerts , null );
176+ }
177+
178+ private static void launchGui (ProgressCallback monitor , File installer , String badCerts , OptionParser parser ) {
173179 try {
174180 UIManager .setLookAndFeel (UIManager .getSystemLookAndFeelClassName ());
175- } catch (Exception e ) { }
181+ } catch (HeadlessException headless ) {
182+ // if ran in a headless CLI environment with no args, show some help text and exit gracefully
183+ if (parser == null ) {
184+ System .out .println ("No options found. Try running with --help for a list of options." );
185+ System .exit (0 );
186+ return ;
187+ }
188+ try {
189+ parser .printHelpOn (System .out );
190+ } catch (IOException ioException ) {
191+ sneak (ioException );
192+ }
193+ System .exit (0 );
194+ return ;
195+ } catch (Exception ignored ) {}
176196
177197 try {
178198 InstallV1 profile = Util .loadInstallProfile ();
@@ -227,4 +247,9 @@ public void write(int b) {
227247 System .setOut (new PrintStream (monitorStream ));
228248 System .setErr (new PrintStream (monitorStream ));
229249 }
250+
251+ @ SuppressWarnings ("unchecked" )
252+ private static <T extends Throwable > void sneak (Throwable t ) throws T {
253+ throw (T ) t ;
254+ }
230255}
0 commit comments