/
list.ts
62 lines (55 loc) · 1.57 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
62
import { cli } from "cli-ux";
import Command from "../../base";
import axios from "axios";
import {
ramSpacing,
cpuSpacing,
diskSpacing,
priceSpacing,
} from "../../utils/spacing";
export default class PlanList extends Command {
static description = "list available plans";
static flags = {
...Command.flags,
...cli.table.flags(),
};
static aliases = ["plan:ls"];
async run() {
const { flags } = this.parse(PlanList);
this.setAxiosConfig({
...this.readGlobalConfig(),
...flags,
});
const {
data: { plans },
} = await axios.get("/v1/me", this.axiosConfig);
const plansData = Object.keys(plans.projects)
.filter((plan) => plan.includes("ir-") && plans.projects[plan].available)
.map((plan) => {
const Plan = plan;
const availablePlan = plans.projects[plan];
const tRAM = availablePlan.RAM.amount;
const RAM = tRAM + ramSpacing(tRAM) + "GB";
const tCPU = availablePlan.CPU.amount;
const CPU = tCPU + cpuSpacing(tCPU) + "Core";
const StorageClass = availablePlan.storageClass;
const tDisk = availablePlan.volume;
const Disk = tDisk + diskSpacing(tDisk) + `GB ${StorageClass}`;
const tPrice = availablePlan.price * 720;
const Price =
tPrice.toLocaleString() + priceSpacing(tPrice) + "Tomans/Month";
return {
Plan,
RAM,
CPU,
Disk,
Price,
};
});
cli.table(
plansData,
{ Plan: {}, RAM: {}, CPU: {}, Disk: {}, Price: {} },
flags
);
}
}