UNPKG

@liara/cli

Version:

The command line interface for Liara

46 lines (45 loc) 1.59 kB
import chalk from 'chalk'; import { ux } from '@oclif/core'; import * as shamsi from 'shamsi-date-converter'; import Command from '../../base.js'; class DatabaseList extends Command { async run() { const { flags } = await this.parse(DatabaseList); await this.setGotConfig(flags); const { databases } = await this.got('v1/databases').json(); if (!databases.length) { this.error(`Not found any database. Please open up https://console.liara.ir/databases and create the database, first.`); } const databasesData = databases.map((db) => { const shamsiData = shamsi.gregorianToJalali(new Date(db.created_at)); const Scale = db.scale === 1 ? chalk.green('ON') : chalk.gray('OFF'); const Status = db.status === 'RUNNING' ? 'OK' : db.status; return { Name: db.hostname, Type: db.type, Plan: db.planID, 'Feature plan': db.bundlePlanID, Status, Scale, 'Created At': `${shamsiData[0]}-${shamsiData[1]}-${shamsiData[2]}`, }; }); ux.table(databasesData, { Name: {}, Type: {}, Plan: {}, 'Feature plan': {}, Scale: {}, Status: {}, 'Created At': {}, }, flags); } } DatabaseList.description = 'list available databases'; DatabaseList.flags = { ...Command.flags, ...ux.table.flags(), }; DatabaseList.aliases = ['db:ls']; export default DatabaseList;