@@ -34,20 +34,16 @@ object Cli {
34
34
nGContext.exit(exit.code)
35
35
}
36
36
37
- private def throwIfError (exit : ExitCode ): Unit = {
38
- if (exit != ExitCode .Ok ) {
39
- throw new RuntimeException (exit.toString) with NoStackTrace
40
- }
41
- }
37
+ private def throwIfError (exit : ExitCode ): Unit = if (exit != ExitCode .Ok )
38
+ throw new RuntimeException (exit.toString) with NoStackTrace
42
39
43
40
def main (args : Array [String ]): Unit = {
44
41
val exit = mainWithOptions(args, CliOptions .default)
45
42
sys.exit(exit.code)
46
43
}
47
44
48
- def exceptionThrowingMain (args : Array [String ]): Unit = {
45
+ def exceptionThrowingMain (args : Array [String ]): Unit =
49
46
exceptionThrowingMainWithOptions(args, CliOptions .default)
50
- }
51
47
52
48
def exceptionThrowingMainWithOptions (
53
49
args : Array [String ],
@@ -57,12 +53,11 @@ object Cli {
57
53
throwIfError(exit)
58
54
}
59
55
60
- def mainWithOptions (args : Array [String ], options : CliOptions ): ExitCode = {
56
+ def mainWithOptions (args : Array [String ], options : CliOptions ): ExitCode =
61
57
getConfig(args, options) match {
62
58
case Some (x) => run(x)
63
59
case None => ExitCode .CommandLineArgumentError
64
60
}
65
- }
66
61
67
62
def getConfig (args : Array [String ], init : CliOptions ): Option [CliOptions ] = {
68
63
val expandedArguments = expandArguments(args)
@@ -81,14 +76,13 @@ object Cli {
81
76
builder.result()
82
77
}
83
78
84
- private [cli] def run (options : CliOptions ): ExitCode = {
79
+ private [cli] def run (options : CliOptions ): ExitCode =
85
80
findRunner(options) match {
86
81
case Left (message) =>
87
82
options.common.err.println(message)
88
83
ExitCode .UnsupportedVersion
89
84
case Right (runner) => runWithRunner(options, runner)
90
85
}
91
- }
92
86
93
87
private val isNativeImage : Boolean = " true" ==
94
88
System .getProperty(" scalafmt.native-image" , " false" )
@@ -125,7 +119,7 @@ object Cli {
125
119
| """ .stripMargin
126
120
)
127
121
} {
128
- case Left (error) => Left (s " error: invalid configuration: ${ error} " )
122
+ case Left (error) => Left (s " error: invalid configuration: $error" )
129
123
case Right (`stableVersion`) =>
130
124
options.common.debug.println(s " Using core runner [ $stableVersion] " )
131
125
Right (ScalafmtCoreRunner )
@@ -162,20 +156,19 @@ object Cli {
162
156
163
157
val exit = runner.run(options, termDisplayMessage)
164
158
165
- if (options.writeMode == WriteMode .Test ) {
166
- if (exit.isOk) {
167
- options.common.out .println(" All files are formatted with scalafmt :)" )
168
- } else if (exit.is(ExitCode .TestError )) {
159
+ if (options.writeMode == WriteMode .Test )
160
+ if (exit.isOk) options.common.out
161
+ .println(" All files are formatted with scalafmt :)" )
162
+ else if (exit.is(ExitCode .TestError )) {
169
163
options.common.out.println(" error: --test failed" )
170
164
options.onTestFailure.foreach(options.common.out.println)
171
- } else { options.common.out.println(s " error: $exit" ) }
172
- }
165
+ } else options.common.out.println(s " error: $exit" )
173
166
if (
174
167
options.writeMode == WriteMode .Test && ! options.fatalWarnings &&
175
168
exit.is(ExitCode .ParseError )
176
- ) {
169
+ )
177
170
// Ignore parse errors etc.
178
171
ExitCode .Ok
179
- } else { exit }
172
+ else exit
180
173
}
181
174
}
0 commit comments