@cto.ai/ops-rc
Version:
💻 CTO.ai Ops - The CLI built for Teams 🚀
62 lines (61 loc) • 2.18 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const base_1 = tslib_1.__importStar(require("./../base"));
const CustomErrors_1 = require("./../errors/CustomErrors");
class Status extends base_1.default {
constructor() {
super(...arguments);
this.getRunningOps = async (config) => {
try {
return (await this.services.api.find(`/private/teams/${config.team.name}/service`, {
headers: {
Authorization: this.accessToken,
},
})).data;
}
catch (err) {
this.debug('%0', err);
this.log(this.ux.colors.whiteBright(`❗ Sorry, we encountered an error trying to list the service status`));
throw new CustomErrors_1.APIError(err);
}
};
this.showServices = (runningServices, config) => {
this.log(this.ux.colors.whiteBright(`Services active on team ${config.team.name}:\n`));
this.ux.table(runningServices, {
name: {
get: ({ name }) => name,
header: 'Service Name',
},
runId: {
get: ({ runId }) => runId,
header: 'Run ID',
},
url: {
get: ({ url }) => url,
header: 'URL',
},
}, { sort: 'name' });
};
}
async run() {
const config = await this.isLoggedIn();
try {
this.parse(Status);
const runningServices = await this.getRunningOps(config);
this.showServices(runningServices, config);
}
catch (err) {
this.debug('%O', err);
this.config.runHook('error', {
err,
accessToken: config.tokens.accessToken,
});
}
}
}
exports.default = Status;
Status.description = 'See the status of currently running Ops (currently only services)';
Status.flags = {
help: base_1.flags.help({ char: 'h' }),
};