Skip to content

Commit

Permalink
Merge pull request #4 from alexarchambault/fix-cli
Browse files Browse the repository at this point in the history
Tweak CLI
  • Loading branch information
alexarchambault authored Jul 4, 2022
2 parents d72311c + 4c0e2d0 commit 45b0deb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
20 changes: 9 additions & 11 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def scalaVersions = Seq("2.12.15", "2.13.8")
def mainScalaVersion = scalaVersions.last

object core extends Cross[Core](scalaVersions: _*)
object cli extends Cross[Cli](scalaVersions: _*)
object cli extends Cli

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

def ghOrg = "scala-cli"
class Cli(val crossScalaVersion: String)
extends CrossSbtModule
with NativeImage
with SnailgunPublishModule {
trait Cli extends SbtModule with NativeImage with SnailgunPublishModule {
def scalaVersion = mainScalaVersion
def moduleDeps = Seq(
core()
core(mainScalaVersion)
)
def ivyDeps = super.ivyDeps() ++ Seq(
ivy"com.github.alexarchambault::case-app:2.1.0-M14"
)
def mainClass = Some("snailgun.Cli")
def mainClass = Some("snailgun.Snailgun")

def nativeImageClassPath = runClasspath()
def nativeImageMainClass = mainClass().getOrElse {
Expand Down Expand Up @@ -197,7 +195,7 @@ private def finalPublishVersion = {
}

def nativeImage = T {
cli(mainScalaVersion).nativeImage()
cli.nativeImage()
}

object ci extends Module {
Expand Down Expand Up @@ -257,7 +255,7 @@ object ci extends Module {
}

def copyLauncher(directory: String = "artifacts") = T.command {
val nativeLauncher = cli(mainScalaVersion).nativeImage().path
val nativeLauncher = cli.nativeImage().path
Upload.copyLauncher(
nativeLauncher,
directory,
Expand All @@ -268,7 +266,7 @@ object ci extends Module {

def copyJvmLauncher(directory: String = "artifacts") = T.command {
val platformExecutableJarExtension = if (Properties.isWin) ".bat" else ""
val launcher = cli(mainScalaVersion).standaloneLauncher().path
val launcher = cli.standaloneLauncher().path
os.copy(
launcher,
os.Path(directory, os.pwd) / s"snailgun$platformExecutableJarExtension",
Expand All @@ -281,7 +279,7 @@ object ci extends Module {
sys.error("UPLOAD_GH_TOKEN not set")
}
def uploadLaunchers(directory: String = "artifacts") = T.command {
val version = cli(mainScalaVersion).publishVersion()
val version = cli.publishVersion()

val path = os.Path(directory, os.pwd)
val launchers = os.list(path).filter(os.isFile(_)).map { path =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import java.io.{InputStream, PrintStream}
import java.net.ConnectException
import java.util.concurrent.atomic.AtomicBoolean

object Cli extends CaseApp[CliOptions] {
object Snailgun extends CaseApp[SnailgunOptions] {
override def stopAtFirstUnrecognized = true
def run(options: CliOptions, args: RemainingArgs): Unit = {
def run(options: SnailgunOptions, args: RemainingArgs): Unit = {
val inOpt = if (options.hasInput) Some(System.in) else None
val out = System.out
val err = System.err
Expand All @@ -33,7 +33,6 @@ object Cli extends CaseApp[CliOptions] {
.orElse(Defaults.env.get("NAILGUN_PORT").map(_.toInt))
.getOrElse(Defaults.Port)
val client = TcpClient(hostServer, portServer)
val noCancel = new AtomicBoolean(false)
val logger = new SnailgunLogger("log", out, isVerbose = options.verbose)
val code =
try
Expand All @@ -44,7 +43,7 @@ object Cli extends CaseApp[CliOptions] {
Defaults.env,
streams,
logger,
noCancel,
new AtomicBoolean(false),
true
)
catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import caseapp._

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

object CliOptions {
implicit lazy val parser: Parser[CliOptions] = Parser.derive
implicit lazy val help: Help[CliOptions] = Help.derive
object SnailgunOptions {
implicit lazy val parser: Parser[SnailgunOptions] = Parser.derive
implicit lazy val help: Help[SnailgunOptions] = Help.derive
}

0 comments on commit 45b0deb

Please sign in to comment.