@devmn/cloud-cli
Version:
CLI tool for Intelligo Cloud.
60 lines • 2.31 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const chalk_1 = require("chalk");
class StdOutUtils {
constructor() {
this.getColoredMachineName = (name) => chalk_1.default.greenBright(name);
this.getColoredMachineUrl = (url) => chalk_1.default.bold.yellow(url);
this.getColoredAppName = (name) => chalk_1.default.magenta(name);
this.getColoredMachine = (machine) => `${this.getColoredMachineName(machine.name)} at ${this.getColoredMachineUrl(machine.baseUrl)}`;
this.displayColoredMachine = (machine) => console.log(`>> ${this.getColoredMachine(machine)}`);
}
printMessage(message, exit = false) {
console.log(message);
if (exit !== false) {
process.exit(exit === true ? 0 : exit);
}
}
printGreenMessage(message, exit = false) {
console.log(`${chalk_1.default.green(message)}`);
if (exit !== false) {
process.exit(exit === true ? 0 : exit);
}
}
printMagentaMessage(message, exit = false) {
console.log(`${chalk_1.default.magenta(message)}`);
// tslint:disable-next-line: no-unused-expression
exit && process.exit(0);
}
printError(error, exit = false) {
console.log(`${chalk_1.default.bold.red(error)}`);
if (exit !== false) {
process.exit(exit === true ? 1 : exit);
}
}
printWarning(warning, exit = false) {
console.log(`${chalk_1.default.yellow(warning)}`);
if (exit !== false) {
process.exit(exit === true ? 1 : exit);
}
}
printTip(tip, exit = false) {
console.log(`${chalk_1.default.bold.green(tip)}`);
if (exit !== false) {
process.exit(exit === true ? 0 : exit);
}
}
errorHandler(error) {
if (error.captainStatus) {
this.printError(`\nError Code: ${error.captainStatus} Message: ${error.captainMessage}\n`, true);
}
else if (error.status) {
this.printError(`\nError status: ${error.status} Message: ${error.description || error.message}\n`, true);
}
else {
this.printError(`\nError: ${error}\n`, true);
}
}
}
exports.default = new StdOutUtils();
//# sourceMappingURL=StdOutUtil.js.map