UNPKG

532 BJavaScriptView Raw
1'use strict'
2
3var util = require('util')
4var cli = require('heroku-cli-util')
5
6function ErrorExit (code) {
7 Error.call(this)
8 Error.captureStackTrace(this, this.constructor)
9 this.name = this.constructor.name
10
11 this.code = code
12}
13
14util.inherits(ErrorExit, Error)
15
16var mocking
17
18function exit (code, message) {
19 if (message) {
20 cli.error(message)
21 }
22 if (mocking) {
23 throw new ErrorExit(code)
24 } else {
25 process.exit(code)
26 }
27}
28
29exit.mock = function () {
30 mocking = true
31}
32
33module.exports = {
34 exit,
35 ErrorExit
36}