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