diff --git a/core/js/src/main/scala/com/monovore/decline/PlatformApp.scala b/core/js/src/main/scala/com/monovore/decline/PlatformApp.scala index 2ffa8ade..979ef905 100644 --- a/core/js/src/main/scala/com/monovore/decline/PlatformApp.scala +++ b/core/js/src/main/scala/com/monovore/decline/PlatformApp.scala @@ -2,6 +2,7 @@ package com.monovore.decline import scala.scalajs.js import scala.scalajs.js.annotation.JSGlobalScope +import js.Dynamic.global object PlatformApp { @@ -21,4 +22,10 @@ object PlatformApp { * otherwise. */ def ambientArgs: Option[Seq[String]] = Process.process.toOption.map { _.argv.drop(2).toSeq } + + private lazy val process = global.require("process") + def exit(code: Int): Nothing = { + process.exit(code) + sys.error(s"Attempt to exit with code $code failed") + } } diff --git a/core/jvm/src/main/scala/com/monovore/decline/PlatformApp.scala b/core/jvm/src/main/scala/com/monovore/decline/PlatformApp.scala index fbccb460..a6b7f278 100644 --- a/core/jvm/src/main/scala/com/monovore/decline/PlatformApp.scala +++ b/core/jvm/src/main/scala/com/monovore/decline/PlatformApp.scala @@ -7,4 +7,8 @@ object PlatformApp { * otherwise. */ def ambientArgs: Option[Seq[String]] = None + + def exit(code: Int): Nothing = { + sys.exit(code) + } } diff --git a/core/native/src/main/scala/com/monovore/decline/PlatformApp.scala b/core/native/src/main/scala/com/monovore/decline/PlatformApp.scala index fbccb460..a6b7f278 100644 --- a/core/native/src/main/scala/com/monovore/decline/PlatformApp.scala +++ b/core/native/src/main/scala/com/monovore/decline/PlatformApp.scala @@ -7,4 +7,8 @@ object PlatformApp { * otherwise. */ def ambientArgs: Option[Seq[String]] = None + + def exit(code: Int): Nothing = { + sys.exit(code) + } } diff --git a/core/shared/src/main/scala/com/monovore/decline/CommandApp.scala b/core/shared/src/main/scala/com/monovore/decline/CommandApp.scala index 5600fb02..02cc2718 100644 --- a/core/shared/src/main/scala/com/monovore/decline/CommandApp.scala +++ b/core/shared/src/main/scala/com/monovore/decline/CommandApp.scala @@ -50,7 +50,9 @@ For suggested usage, see: http://monovore.com/decline/usage.html#defining-an-app ) final def main(args: Array[String]): Unit = command.parse(PlatformApp.ambientArgs getOrElse args, sys.env) match { - case Left(help) => System.err.println(help) + case Left(help) => + System.err.println(help) + PlatformApp.exit(1) case Right(_) => () } }