1 | 'use strict'
|
2 |
|
3 | var util = require('util')
|
4 | var cli = require('heroku-cli-util')
|
5 |
|
6 | function 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 |
|
14 | util.inherits(ErrorExit, Error)
|
15 |
|
16 | var mocking
|
17 |
|
18 | function 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 |
|
29 | exit.mock = function () {
|
30 | mocking = true
|
31 | }
|
32 |
|
33 | module.exports = {
|
34 | exit,
|
35 | ErrorExit
|
36 | }
|