Skip to content

Instantly share code, notes, and snippets.

@ches
Created February 16, 2019 12:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ches/01107b3761de199b8b4763e835de5034 to your computer and use it in GitHub Desktop.
Save ches/01107b3761de199b8b4763e835de5034 to your computer and use it in GitHub Desktop.
A cute little application exit status value class
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