6161 })
6262public class Main {
6363
64+ static boolean verbose = false ;
65+
66+ @ Mixin VerboseMixin verboseMixin ;
67+
6468 @ Command (
6569 name = "copy" ,
6670 aliases = {"c" },
@@ -69,6 +73,7 @@ public class Main {
6973 + "By default jpm will try to create symbolic links to conserve space.\n \n "
7074 + "Example:\n jpm copy org.apache.httpcomponents:httpclient:4.5.14\n " )
7175 static class Copy implements Callable <Integer > {
76+ @ Mixin VerboseMixin verboseMixin ;
7277 @ Mixin QuietMixin quietMixin ;
7378 @ Mixin ArtifactsMixin artifactsMixin ;
7479
@@ -107,6 +112,7 @@ public Integer call() throws Exception {
107112 + "match the given (partial) name.\n \n "
108113 + "Example:\n jpm search httpclient\n " )
109114 static class Search implements Callable <Integer > {
115+ @ Mixin VerboseMixin verboseMixin ;
110116 @ Mixin QuietMixin quietMixin ;
111117 @ Mixin DepsMixin depsMixin ;
112118
@@ -290,6 +296,7 @@ private static String getSelectedId(
290296 + "If no artifacts are passed the app.yml file will be left untouched and only the existing dependencies in the file will be copied.\n \n "
291297 + "Example:\n jpm install org.apache.httpcomponents:httpclient:4.5.14\n " )
292298 static class Install implements Callable <Integer > {
299+ @ Mixin VerboseMixin verboseMixin ;
293300 @ Mixin QuietMixin quietMixin ;
294301 @ Mixin OptionalArtifactsMixin optionalArtifactsMixin ;
295302
@@ -318,6 +325,7 @@ public Integer call() throws Exception {
318325 + "If no artifacts are passed the classpath for the dependencies defined in the app.yml file will be printed instead.\n \n "
319326 + "Example:\n jpm path org.apache.httpcomponents:httpclient:4.5.14\n " )
320327 static class PrintPath implements Callable <Integer > {
328+ @ Mixin VerboseMixin verboseMixin ;
321329 @ Mixin OptionalArtifactsMixin optionalArtifactsMixin ;
322330
323331 @ Override
@@ -367,6 +375,7 @@ public Integer call() throws Exception {
367375 + " jpm exec javac -cp {{deps}} -d out/classes --source-path src/main/java App.java\n "
368376 + " jpm exec @kotlinc -cp {{deps}} -d out/classes src/main/kotlin/App.kt\n " )
369377 static class Exec implements Callable <Integer > {
378+ @ Mixin VerboseMixin verboseMixin ;
370379 @ Mixin DepsMixin depsMixin ;
371380 @ Mixin QuietMixin quietMixin ;
372381
@@ -403,6 +412,7 @@ public Integer call() throws Exception {
403412 + " jpm do test --arg verbose\n "
404413 + " jpm do build -a --fresh test -a verbose\n " )
405414 static class Do implements Callable <Integer > {
415+ @ Mixin VerboseMixin verboseMixin ;
406416 @ Mixin DepsMixin depsMixin ;
407417 @ Mixin QuietMixin quietMixin ;
408418
@@ -496,6 +506,7 @@ public Integer call() throws Exception {
496506 }
497507
498508 abstract static class DoAlias implements Callable <Integer > {
509+ @ Mixin VerboseMixin verboseMixin ;
499510 @ Mixin DepsMixin depsMixin ;
500511
501512 @ Unmatched List <String > args = new ArrayList <>();
@@ -628,6 +639,15 @@ static class OptionalArtifactsMixin extends BaseArtifactsMixin {
628639 private String [] artifactNames = {};
629640 }
630641
642+ static class VerboseMixin {
643+ @ Option (
644+ names = {"-v" , "--verbose" },
645+ description = "Enable verbose output for debugging" )
646+ public void setVerbose (boolean verbose ) {
647+ Main .verbose = verbose ;
648+ }
649+ }
650+
631651 static class QuietMixin {
632652 @ Option (
633653 names = {"-q" , "--quiet" },
@@ -642,11 +662,24 @@ private static void printStats(SyncResult stats) {
642662 (Integer ) stats .copied , (Integer ) stats .updated , (Integer ) stats .deleted );
643663 }
644664
665+ static CommandLine .IExecutionExceptionHandler errorHandler =
666+ (ex , commandLine , parseResult ) -> {
667+ System .err .println ("Error: " + ex .getMessage ());
668+ if (verbose ) {
669+ ex .printStackTrace ();
670+ } else {
671+ System .err .println (
672+ "(Run with --verbose for more details. If you believe you found a bug in jpm, open an issue at https://github.com/codejive/java-jpm/issues)" );
673+ }
674+ return commandLine .getCommandSpec ().exitCodeOnExecutionException ();
675+ };
676+
645677 public static CommandLine getCommandLine () {
646678 return new CommandLine (new Main ())
647679 .setStopAtPositional (true )
648680 .setAllowOptionsAsOptionParameters (true )
649- .setAllowSubcommandsAsOptionParameters (true );
681+ .setAllowSubcommandsAsOptionParameters (true )
682+ .setExecutionExceptionHandler (errorHandler );
650683 }
651684
652685 /**
0 commit comments