@@ -66,34 +66,43 @@ object Run extends ScalaCommand[RunOptions] {
66
66
def maybeRun (
67
67
build : Build .Successful ,
68
68
allowTerminate : Boolean
69
- ): Either [BuildException , (Process , CompletableFuture [_])] = either {
69
+ ): Either [BuildException , Option [ (Process , CompletableFuture [_])] ] = either {
70
70
val potentialMainClasses = build.foundMainClasses()
71
- value(options.mainClass.maybePrintMainClasses(potentialMainClasses))
72
- val process = value(maybeRunOnce(
73
- build,
74
- programArgs,
75
- logger,
76
- allowExecve = allowTerminate,
77
- jvmRunner = build.artifacts.hasJvmRunner,
78
- potentialMainClasses
79
- ))
71
+ if (options.mainClass.mainClassLs.contains(true ))
72
+ value {
73
+ options.mainClass
74
+ .maybePrintMainClasses(potentialMainClasses, shouldExit = allowTerminate)
75
+ .map(_ => None )
76
+ }
77
+ else {
78
+ val process = value {
79
+ maybeRunOnce(
80
+ build,
81
+ programArgs,
82
+ logger,
83
+ allowExecve = allowTerminate,
84
+ jvmRunner = build.artifacts.hasJvmRunner,
85
+ potentialMainClasses
86
+ )
87
+ }
80
88
81
- val onExitProcess = process.onExit().thenApply { p1 =>
82
- val retCode = p1.exitValue()
83
- if (retCode != 0 )
84
- if (allowTerminate)
85
- sys.exit(retCode)
86
- else {
87
- val red = Console .RED
88
- val lightRed = " \u001b [91m"
89
- val reset = Console .RESET
90
- System .err.println(
91
- s " ${red}Program exited with return code $lightRed$retCode$red. $reset"
92
- )
93
- }
94
- }
89
+ val onExitProcess = process.onExit().thenApply { p1 =>
90
+ val retCode = p1.exitValue()
91
+ if (retCode != 0 )
92
+ if (allowTerminate)
93
+ sys.exit(retCode)
94
+ else {
95
+ val red = Console .RED
96
+ val lightRed = " \u001b [91m"
97
+ val reset = Console .RESET
98
+ System .err.println(
99
+ s " ${red}Program exited with return code $lightRed$retCode$red. $reset"
100
+ )
101
+ }
102
+ }
95
103
96
- (process, onExitProcess)
104
+ Some ((process, onExitProcess))
105
+ }
97
106
}
98
107
99
108
val cross = options.compileCross.cross.getOrElse(false )
@@ -130,6 +139,7 @@ object Run extends ScalaCommand[RunOptions] {
130
139
if (proc.isAlive) ProcUtil .forceKillProcess(proc, logger)
131
140
val maybeProcess = maybeRun(s, allowTerminate = false )
132
141
.orReport(logger)
142
+ .flatten
133
143
if (options.watch.restart)
134
144
processOpt = maybeProcess
135
145
else
@@ -158,7 +168,7 @@ object Run extends ScalaCommand[RunOptions] {
158
168
builds.main match {
159
169
case s : Build .Successful =>
160
170
val (process, onExit) = maybeRun(s, allowTerminate = true )
161
- .orExit(logger)
171
+ .orExit(logger).getOrElse(sys.exit( 1 ))
162
172
ProcUtil .waitForProcess(process, onExit)
163
173
case _ : Build .Failed =>
164
174
System .err.println(" Compilation failed" )
0 commit comments