/
list.ts
56 lines (48 loc) · 1.32 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
import { cli } from "cli-ux";
import Command, { IGetProjectsResponse } from "../../base";
import axios from "axios";
import * as shamsi from "shamsi-date-converter";
export default class AppList extends Command {
static description = "list available apps";
static flags = {
...Command.flags,
...cli.table.flags(),
};
static aliases = ["app:ls"];
async run() {
const { flags } = this.parse(AppList);
this.setAxiosConfig({
...this.readGlobalConfig(),
...flags,
});
const {
data: { projects },
} = await axios.get<IGetProjectsResponse>("/v1/projects", this.axiosConfig);
if (projects.length === 0) {
this.error("Please create an app via 'liara app:create' command, first.");
}
const appsData = projects.map((project) => {
const shamshiDate = shamsi.gregorianToJalali(new Date(project.created_at))
return {
Name: project.project_id,
Platform: project.type,
Plan: project.planID,
Status: project.status,
Scale: project.scale,
"Created At": `${shamshiDate[0]}-${shamshiDate[1]}-${shamshiDate[2]}`,
};
});
cli.table(
appsData,
{
Name: {},
Platform: {},
Plan: {},
Scale: {},
Status: {},
"Created At": {},
},
flags
);
}
}