Skip to content

Commit 45b0deb

Browse files
Merge pull request #4 from alexarchambault/fix-cli
Tweak CLI
2 parents d72311c + 4c0e2d0 commit 45b0deb

File tree

3 files changed

+16
-19
lines changed

3 files changed

+16
-19
lines changed

build.sc

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def scalaVersions = Seq("2.12.15", "2.13.8")
2020
def mainScalaVersion = scalaVersions.last
2121

2222
object core extends Cross[Core](scalaVersions: _*)
23-
object cli extends Cross[Cli](scalaVersions: _*)
23+
object cli extends Cli
2424

2525
class Core(val crossScalaVersion: String) extends CrossSbtModule with SnailgunPublishModule {
2626
object test extends Tests {
@@ -36,17 +36,15 @@ class Core(val crossScalaVersion: String) extends CrossSbtModule with SnailgunPu
3636
}
3737

3838
def ghOrg = "scala-cli"
39-
class Cli(val crossScalaVersion: String)
40-
extends CrossSbtModule
41-
with NativeImage
42-
with SnailgunPublishModule {
39+
trait Cli extends SbtModule with NativeImage with SnailgunPublishModule {
40+
def scalaVersion = mainScalaVersion
4341
def moduleDeps = Seq(
44-
core()
42+
core(mainScalaVersion)
4543
)
4644
def ivyDeps = super.ivyDeps() ++ Seq(
4745
ivy"com.github.alexarchambault::case-app:2.1.0-M14"
4846
)
49-
def mainClass = Some("snailgun.Cli")
47+
def mainClass = Some("snailgun.Snailgun")
5048

5149
def nativeImageClassPath = runClasspath()
5250
def nativeImageMainClass = mainClass().getOrElse {
@@ -197,7 +195,7 @@ private def finalPublishVersion = {
197195
}
198196

199197
def nativeImage = T {
200-
cli(mainScalaVersion).nativeImage()
198+
cli.nativeImage()
201199
}
202200

203201
object ci extends Module {
@@ -257,7 +255,7 @@ object ci extends Module {
257255
}
258256

259257
def copyLauncher(directory: String = "artifacts") = T.command {
260-
val nativeLauncher = cli(mainScalaVersion).nativeImage().path
258+
val nativeLauncher = cli.nativeImage().path
261259
Upload.copyLauncher(
262260
nativeLauncher,
263261
directory,
@@ -268,7 +266,7 @@ object ci extends Module {
268266

269267
def copyJvmLauncher(directory: String = "artifacts") = T.command {
270268
val platformExecutableJarExtension = if (Properties.isWin) ".bat" else ""
271-
val launcher = cli(mainScalaVersion).standaloneLauncher().path
269+
val launcher = cli.standaloneLauncher().path
272270
os.copy(
273271
launcher,
274272
os.Path(directory, os.pwd) / s"snailgun$platformExecutableJarExtension",
@@ -281,7 +279,7 @@ object ci extends Module {
281279
sys.error("UPLOAD_GH_TOKEN not set")
282280
}
283281
def uploadLaunchers(directory: String = "artifacts") = T.command {
284-
val version = cli(mainScalaVersion).publishVersion()
282+
val version = cli.publishVersion()
285283

286284
val path = os.Path(directory, os.pwd)
287285
val launchers = os.list(path).filter(os.isFile(_)).map { path =>

cli/src/main/scala/snailgun/Cli.scala renamed to cli/src/main/scala/snailgun/Snailgun.scala

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import java.io.{InputStream, PrintStream}
99
import java.net.ConnectException
1010
import java.util.concurrent.atomic.AtomicBoolean
1111

12-
object Cli extends CaseApp[CliOptions] {
12+
object Snailgun extends CaseApp[SnailgunOptions] {
1313
override def stopAtFirstUnrecognized = true
14-
def run(options: CliOptions, args: RemainingArgs): Unit = {
14+
def run(options: SnailgunOptions, args: RemainingArgs): Unit = {
1515
val inOpt = if (options.hasInput) Some(System.in) else None
1616
val out = System.out
1717
val err = System.err
@@ -33,7 +33,6 @@ object Cli extends CaseApp[CliOptions] {
3333
.orElse(Defaults.env.get("NAILGUN_PORT").map(_.toInt))
3434
.getOrElse(Defaults.Port)
3535
val client = TcpClient(hostServer, portServer)
36-
val noCancel = new AtomicBoolean(false)
3736
val logger = new SnailgunLogger("log", out, isVerbose = options.verbose)
3837
val code =
3938
try
@@ -44,7 +43,7 @@ object Cli extends CaseApp[CliOptions] {
4443
Defaults.env,
4544
streams,
4645
logger,
47-
noCancel,
46+
new AtomicBoolean(false),
4847
true
4948
)
5049
catch {

cli/src/main/scala/snailgun/CliOptions.scala renamed to cli/src/main/scala/snailgun/SnailgunOptions.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import caseapp._
44

55
// format: off
66
@ArgsName("The command and arguments for the Nailgun server")
7-
final case class CliOptions(
7+
final case class SnailgunOptions(
88
@HelpMessage("Specify the host name of the target Nailgun server")
99
nailgunServer: Option[String] = None,
1010
@HelpMessage("Specify the port of the target Nailgun server")
@@ -18,7 +18,7 @@ final case class CliOptions(
1818
)
1919
// format: on
2020

21-
object CliOptions {
22-
implicit lazy val parser: Parser[CliOptions] = Parser.derive
23-
implicit lazy val help: Help[CliOptions] = Help.derive
21+
object SnailgunOptions {
22+
implicit lazy val parser: Parser[SnailgunOptions] = Parser.derive
23+
implicit lazy val help: Help[SnailgunOptions] = Help.derive
2424
}

0 commit comments

Comments
 (0)