|
1 | 1 | package scala.cli.commands
|
2 | 2 |
|
| 3 | +import caseapp._ |
3 | 4 | import caseapp.core.help.RuntimeCommandsHelp
|
| 5 | +import caseapp.core.{Error, RemainingArgs} |
4 | 6 |
|
5 |
| -import scala.cli.ScalaCliHelp |
| 7 | +import scala.build.internal.Constants |
| 8 | +import scala.cli.{CurrentParams, ScalaCliHelp} |
6 | 9 |
|
7 |
| -// FIXME scalafmt formats that really weirdly, need to investigate why |
8 |
| -// format: off |
9 |
| -class Default(help: => RuntimeCommandsHelp) extends DefaultBase( |
10 |
| - help.help(ScalaCliHelp.helpFormat), |
11 |
| - help.help(ScalaCliHelp.helpFormat, showHidden = true) |
12 |
| -) |
13 |
| -// format: on |
| 10 | +class Default( |
| 11 | + actualHelp: => RuntimeCommandsHelp |
| 12 | +) extends ScalaCommand[DefaultOptions] { |
| 13 | + |
| 14 | + private def defaultHelp: String = actualHelp.help(ScalaCliHelp.helpFormat) |
| 15 | + private def defaultFullHelp: String = actualHelp.help(ScalaCliHelp.helpFormat, showHidden = true) |
| 16 | + |
| 17 | + override protected def commandLength = 0 |
| 18 | + |
| 19 | + override def group = "Main" |
| 20 | + override def sharedOptions(options: DefaultOptions) = |
| 21 | + Some[scala.cli.commands.SharedOptions](options.runOptions.shared) |
| 22 | + private[cli] var anyArgs = false |
| 23 | + override def helpAsked(progName: String, maybeOptions: Either[Error, DefaultOptions]): Nothing = { |
| 24 | + println(defaultHelp) |
| 25 | + sys.exit(0) |
| 26 | + } |
| 27 | + override def fullHelpAsked(progName: String): Nothing = { |
| 28 | + println(defaultFullHelp) |
| 29 | + sys.exit(0) |
| 30 | + } |
| 31 | + def run(options: DefaultOptions, args: RemainingArgs): Unit = { |
| 32 | + CurrentParams.verbosity = options.runOptions.shared.logging.verbosity |
| 33 | + if (options.version) |
| 34 | + println(Constants.version) |
| 35 | + else if (anyArgs) |
| 36 | + Run.run( |
| 37 | + options.runOptions, |
| 38 | + args |
| 39 | + ) |
| 40 | + else |
| 41 | + helpAsked(finalHelp.progName, Right(options)) |
| 42 | + } |
| 43 | +} |
0 commit comments