UNPKG

@liara/cli

Version:

The command line interface for Liara

45 lines (44 loc) 1.37 kB
import { ux } from '@oclif/core'; import Command from '../../base.js'; import { IAAS_API_URL } from '../../constants.js'; import ora from 'ora'; import * as shamsi from 'shamsi-date-converter'; class VmList extends Command { async setGotConfig(config) { await super.setGotConfig(config); this.got = this.got.extend({ prefixUrl: IAAS_API_URL, }); } async run() { const { flags } = await this.parse(VmList); await this.setGotConfig(flags); this.spinner = ora(); const vms = await this.getVms('There are no active vms.', (vm) => vm.state !== 'DELETING'); const vmsData = vms.map((vm) => { const shamshiDate = shamsi.gregorianToJalali(new Date(vm.createdAt)); return { Name: vm.name, Plan: vm.plan, OS: vm.OS, State: vm.state, Power: vm.power, 'Created At': `${shamshiDate[0]}-${shamshiDate[1]}-${shamshiDate[2]}`, }; }); ux.table(vmsData, { Name: {}, Plan: {}, OS: {}, State: {}, Power: {}, 'Created At': {}, }, flags); } } VmList.flags = { ...Command.flags, ...ux.table.flags(), }; VmList.description = 'list available vms'; export default VmList;