steadybit
Version:
Command-line interface to interact with the Steadybit API
45 lines • 2.1 kB
JavaScript
;
// SPDX-License-Identifier: MIT
// SPDX-FileCopyrightText: 2024 Steadybit GmbH
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateAdviceStatus = validateAdviceStatus;
const api_1 = require("./api");
const console_table_printer_1 = require("console-table-printer");
const errors_1 = require("../errors");
const red_color = 'red';
const green_color = 'green';
function validateAdviceStatus(options) {
return __awaiter(this, void 0, void 0, function* () {
const allAdvice = yield (0, api_1.fetchAllAdvice)(options.environment, options.query);
if (allAdvice.length === 0) {
return;
}
let errorCount = 0;
const p = new console_table_printer_1.Table();
for (const advice of allAdvice) {
const statusMatch = advice.advice.status === options.status;
if (!statusMatch) {
errorCount++;
}
p.addRow({
target: advice.target.reference,
advice: advice.advice.label,
status: advice.advice.status,
}, { color: statusMatch ? green_color : red_color });
}
p.printTable();
if (errorCount > 0) {
throw (0, errors_1.abortExecution)('%d of %d advice did not match the expected status.', errorCount, allAdvice.length);
}
});
}
//# sourceMappingURL=validateStatus.js.map