/
list.js
62 lines (53 loc) · 1.6 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
const { cli } = require('cli-ux')
const { getProject } = require('../../requests/project')
const { getResponseContent } = require('../../support/command/handle-response')
const BaseCommand = require('../../support/command/base-command')
class ListProjectCommand extends BaseCommand {
constructor(...props) {
super(...props)
this.logProject = this.logProject.bind(this)
}
async run() {
const { args } = this.parse(ListProjectCommand)
await this.listProjects(args['OWNER'])
}
async logProject(response) {
const responseObj = JSON.parse(await getResponseContent(response))
if (responseObj.projects.length === 0){
this.log('No projects found.')
} else {
cli.table(responseObj.projects, {
name: {},
owner: {},
description: {},
apis: {
header: 'APIs'
},
domains: {}
}, {
printLine: this.log
})
}
}
async listProjects(args) {
return this.executeHttp({
execute: () => getProject([args]),
onResolve: this.logProject,
options: {}
})
}
}
ListProjectCommand.description = 'list projects'
ListProjectCommand.examples = [
'swaggerhub project:list',
'swaggerhub project:list organization'
]
ListProjectCommand.args = [{
name: 'OWNER',
required: false,
description: 'Organization to list projects for'
}]
ListProjectCommand.flags = {
...BaseCommand.flags
}
module.exports = ListProjectCommand