-
Notifications
You must be signed in to change notification settings - Fork 12
/
list.ts
64 lines (55 loc) · 1.54 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
63
64
import { ux } from '@oclif/core';
import Command, { IConfig, IGetBucketsResponse } from '../../base.js';
import * as shamsi from 'shamsi-date-converter';
import {
OBJECT_STORAGE_API_URL_DEV,
OBJECT_STORAGE_API_URL,
DEV_MODE,
} from '../../constants.js';
export default class BucketList extends Command {
static description = 'list available buckets';
static flags = {
...Command.flags,
...ux.table.flags(),
};
static aliases = ['bucket:ls'];
async setGotConfig(config: IConfig): Promise<void> {
await super.setGotConfig(config);
this.got = this.got.extend({
prefixUrl: DEV_MODE ? OBJECT_STORAGE_API_URL_DEV : OBJECT_STORAGE_API_URL,
});
}
async run() {
const { flags } = await this.parse(BucketList);
await this.setGotConfig(flags);
const { buckets } = await this.got(
'api/v1/buckets'
).json<IGetBucketsResponse>();
if (buckets.length === 0) {
this.error(
"Please create an bucket via 'liara bucket:create' command, first."
);
}
const bucketsData = buckets.map((bucket) => {
const shamshiDate = shamsi.gregorianToJalali(new Date(bucket.createdAt));
return {
Name: bucket.name,
Plan: bucket.plan,
Status: bucket.status,
Permission: bucket.permission,
'Created At': `${shamshiDate[0]}-${shamshiDate[1]}-${shamshiDate[2]}`,
};
});
ux.table(
bucketsData,
{
Name: {},
Plan: {},
Status: {},
Permission: {},
'Created At': {},
},
flags
);
}
}