-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathlist.ts
61 lines (50 loc) · 1.51 KB
/
list.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import chalk from 'chalk';
import { ux } from '@oclif/core';
import * as shamsi from 'shamsi-date-converter';
import Command from '../../base.js';
import IGetDatabasesResponse from '../../types/get-dbs-response.js';
export default class DatabaseList extends Command {
static description = 'list available databases';
static flags = {
...Command.flags,
...ux.table.flags(),
};
static aliases: string[] = ['db:ls'];
async run() {
const { flags } = await this.parse(DatabaseList);
await this.setGotConfig(flags);
const { databases } =
await this.got('v1/databases').json<IGetDatabasesResponse>();
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,
);
}
}