UNPKG

ivr-tester-cli

Version:

CLI for automated testing of IVR call flows

34 lines (33 loc) 1.29 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.createProgram = void 0; /** * Creates program from a command that can unifies the exit strategy between the Command and the rest * of the app (i.e. whether to suppress the default behaviour of exiting the process), and outputs * text to the terminal in the same way - making capturing console output for testing easier. * * As I learn more about commands it might make more sense to separate the concept of a Program from Commander's * Command, especially since Commander's responsibilities end when it has parsed the Command line, outputting logs * and how to exit the program after this isn't its concern. */ function createProgram(command, suppressProcessExit) { if (suppressProcessExit) { command.exitOverride(); } return { command, writeOut(message) { command.configureOutput().writeOut(`${message.trimRight()}\n`); }, exit(message) { command.configureOutput().writeErr(`${message.trimRight()}\n`); if (suppressProcessExit) { throw Error(message); } else { process.exit(1); } }, }; } exports.createProgram = createProgram;