Created
February 16, 2019 12:08
-
-
Save ches/01107b3761de199b8b4763e835de5034 to your computer and use it in GitHub Desktop.
A cute little application exit status value class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scala.language.implicitConversions | |
/** A process exit status. */ | |
sealed abstract class ExitStatus(val code: Int) extends Product with Serializable | |
/** Exit statuses used conventionally across components. */ | |
object ExitStatus { | |
case object Success extends ExitStatus(0) | |
case object Error extends ExitStatus(1) | |
case object BadUsage extends ExitStatus(2) // 2 is conventional, e.g. bash builtins, grep | |
case object NoOp extends ExitStatus(3) // Nothing done, e.g. could not get ZooKeeper lock | |
/** An innocent little conversion to give you the pleasing syntax of | |
* {{{ | |
* sys.exit(ExitStatus.Success) | |
* }}} | |
*/ | |
implicit def exitStatus2int(status: ExitStatus): Int = status.code | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment