UNPKG

@liara/cli

Version:

The command line interface for Liara

47 lines (46 loc) 1.64 kB
import { ux } from '@oclif/core'; import Command from '../../base.js'; import * as shamsi from 'shamsi-date-converter'; import { MAIL_SERVICE_URL, DEV_MODE, MAIL_SERVICE_URL_DEV, } from '../../constants.js'; class MailList extends Command { async setGotConfig(config) { await super.setGotConfig(config); this.got = this.got.extend({ prefixUrl: DEV_MODE ? MAIL_SERVICE_URL_DEV : MAIL_SERVICE_URL, }); } async run() { const { flags } = await this.parse(MailList); await this.setGotConfig(flags); const { data } = await this.got('api/v1/mails').json(); if (data.mailServers.length === 0) { this.error("Please create a mail server via 'liara mail:create' command, first."); } const mailsData = data.mailServers.map((mail) => { const shamshiDate = shamsi.gregorianToJalali(new Date(mail.createdAt)); return { plan: mail.plan.name, domain: mail.domain, recordsStatus: mail.recordsStatus, mode: mail.mode, status: mail.status, 'Created At': `${shamshiDate[0]}-${shamshiDate[1]}-${shamshiDate[2]}`, }; }); ux.table(mailsData, { plan: {}, domain: {}, recordsStatus: {}, mode: {}, status: {}, 'Created At': {}, }, flags); } } MailList.description = 'list available mail servers'; MailList.flags = { ...Command.flags, ...ux.table.flags(), }; MailList.aliases = ['mail:ls']; export default MailList;