This repository has been archived by the owner on Nov 3, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
list.js
108 lines (97 loc) · 2.93 KB
/
list.js
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const {flags} = require('@oclif/command');
const BaseCommand = require('../../base');
class ActionsListCommand extends BaseCommand {
async run() {
const {flags} = this.parse(ActionsListCommand);
const {json, page} = flags;
const {api, styledJSON, spinner} = this;
const options = {
columns: flags.columns,
sort: flags.sort,
filter: flags.filter,
csv: flags.csv,
extended: flags.extended,
'no-truncate': flags['no-truncate'],
'no-header': flags['no-header']
};
const columns = {
id: {
header: 'ID'
},
resource_id: {},
resource_type: {},
region: {},
status: {},
type: {},
started_at: {},
completed_at: {}
};
try {
spinner.start('Loading actions...');
const {body} = await api.accountGetActions({page});
spinner.stop();
if (json) {
this.log(styledJSON(body));
} else if (body.meta.total === 0) {
this.log("You haven't perfomed any actions");
} else {
const {cli} = require('cli-ux');
const {calculatePages} = require('../../common');
const data = [];
body.actions.map(action =>
data.push({
id: action.id,
status: action.status,
resource_type: action.resource_type,
resource_id: action.resource_id,
type: action.type,
started_at: new Date(action.started_at).toUTCString(),
completed_at: new Date(action.completed_at).toUTCString(),
region: action.region_slug
})
);
const {currentPage, totalPages} = calculatePages(body.links);
cli.table(data, columns, options);
if (totalPages > 1) {
this.log('Current Page:', currentPage);
this.log('Total Pages:', totalPages);
}
}
} catch (error) {
spinner.stop();
this.error(error.message);
}
}
}
ActionsListCommand.description = 'List all executed actions';
ActionsListCommand.flags = {
columns: flags.string({
exclusive: ['additional'],
description: 'only show provided columns (comma-seperated)'
}),
sort: flags.string({
description: 'property to sort by (prepend ' - ' for descending)'
}),
filter: flags.string({
description: 'filter property by partial string matching, ex: name=foo'
}),
csv: flags.boolean({
exclusive: ['no-truncate'],
description: 'output is csv format'
}),
extended: flags.boolean({char: 'x', description: 'show extra columns'}),
'no-truncate': flags.boolean({
exclusive: ['csv'],
description: 'do not truncate output to fit screen'
}),
'no-header': flags.boolean({
exclusive: ['csv'],
description: 'hide table header from output'
}),
json: flags.boolean({char: 'j', description: 'output in json format'}),
page: flags.integer({
char: 'p',
description: 'specific page to request'
})
};
module.exports = ActionsListCommand;