swaggerhub-cli 0.5.0 → 0.6.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +260 -58
- package/oclif.manifest.json +1 -1
- package/package.json +11 -8
- package/src/commands/project/api/add.js +48 -0
- package/src/commands/project/api/remove.js +69 -0
- package/src/commands/project/create.js +77 -0
- package/src/commands/project/delete.js +44 -0
- package/src/commands/project/domain/add.js +48 -0
- package/src/commands/project/domain/remove.js +69 -0
- package/src/commands/project/get.js +51 -0
- package/src/commands/project/list.js +62 -0
- package/src/commands/project/member/list.js +60 -0
- package/src/format-readme.js +38 -0
- package/src/help.js +1 -1
- package/src/requests/project.js +20 -0
- package/src/support/command/parse-input.js +14 -0
- package/src/template-strings/info.js +16 -1
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const { cli } = require('cli-ux')
|
|
2
|
+
const { getProject } = require('../../requests/project')
|
|
3
|
+
const { getResponseContent } = require('../../support/command/handle-response')
|
|
4
|
+
const BaseCommand = require('../../support/command/base-command')
|
|
5
|
+
|
|
6
|
+
class ListProjectCommand extends BaseCommand {
|
|
7
|
+
constructor(...props) {
|
|
8
|
+
super(...props)
|
|
9
|
+
this.logProject = this.logProject.bind(this)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async run() {
|
|
13
|
+
const { args } = this.parse(ListProjectCommand)
|
|
14
|
+
await this.listProjects(args['OWNER'])
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
async logProject(response) {
|
|
18
|
+
const responseObj = JSON.parse(await getResponseContent(response))
|
|
19
|
+
if (responseObj.projects.length === 0){
|
|
20
|
+
this.log('No projects found.')
|
|
21
|
+
} else {
|
|
22
|
+
cli.table(responseObj.projects, {
|
|
23
|
+
name: {},
|
|
24
|
+
owner: {},
|
|
25
|
+
description: {},
|
|
26
|
+
apis: {
|
|
27
|
+
header: 'APIs'
|
|
28
|
+
},
|
|
29
|
+
domains: {}
|
|
30
|
+
}, {
|
|
31
|
+
printLine: this.log
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async listProjects(args) {
|
|
37
|
+
return this.executeHttp({
|
|
38
|
+
execute: () => getProject([args]),
|
|
39
|
+
onResolve: this.logProject,
|
|
40
|
+
options: {}
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
ListProjectCommand.description = 'list projects'
|
|
46
|
+
|
|
47
|
+
ListProjectCommand.examples = [
|
|
48
|
+
'swaggerhub project:list',
|
|
49
|
+
'swaggerhub project:list organization'
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
ListProjectCommand.args = [{
|
|
53
|
+
name: 'OWNER',
|
|
54
|
+
required: false,
|
|
55
|
+
description: 'Organization to list projects for'
|
|
56
|
+
}]
|
|
57
|
+
|
|
58
|
+
ListProjectCommand.flags = {
|
|
59
|
+
...BaseCommand.flags
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
module.exports = ListProjectCommand
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
const { getProject } = require('../../../requests/project')
|
|
2
|
+
const { getResponseContent } = require('../../../support/command/handle-response')
|
|
3
|
+
const BaseCommand = require('../../../support/command/base-command')
|
|
4
|
+
const { getProjectIdentifierArg } = require('../../../support/command/parse-input')
|
|
5
|
+
const { cli } = require('cli-ux')
|
|
6
|
+
|
|
7
|
+
class ListProjectMembersCommand extends BaseCommand {
|
|
8
|
+
constructor(...props) {
|
|
9
|
+
super(...props)
|
|
10
|
+
this.logProjectMembers = this.logProjectMembers.bind(this)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
async run() {
|
|
14
|
+
const { args } = this.parse(ListProjectMembersCommand)
|
|
15
|
+
const projectPath = getProjectIdentifierArg(args)
|
|
16
|
+
await this.getProjectMembers(projectPath)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
async logProjectMembers(response) {
|
|
20
|
+
const responseObj = JSON.parse(await getResponseContent(response))
|
|
21
|
+
if (responseObj.members.length === 0){
|
|
22
|
+
this.log('No members found.')
|
|
23
|
+
} else {
|
|
24
|
+
cli.table(responseObj.members, {
|
|
25
|
+
name: {
|
|
26
|
+
minWidth: 24
|
|
27
|
+
},
|
|
28
|
+
type: {}
|
|
29
|
+
}, {
|
|
30
|
+
printLine: this.log
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
async getProjectMembers(projectPath) {
|
|
36
|
+
return this.executeHttp({
|
|
37
|
+
execute: () => getProject([projectPath,'members']),
|
|
38
|
+
onResolve: this.logProjectMembers,
|
|
39
|
+
options: {}
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
ListProjectMembersCommand.description = 'list members of a project'
|
|
45
|
+
|
|
46
|
+
ListProjectMembersCommand.examples = [
|
|
47
|
+
'swaggerhub project:member:list organisation/project_name',
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
ListProjectMembersCommand.args = [{
|
|
51
|
+
name: 'OWNER/PROJECT_NAME',
|
|
52
|
+
required: true,
|
|
53
|
+
description: 'Project to list members of'
|
|
54
|
+
}]
|
|
55
|
+
|
|
56
|
+
ListProjectMembersCommand.flags = {
|
|
57
|
+
...BaseCommand.flags
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
module.exports = ListProjectMembersCommand
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const fs = require('fs')
|
|
2
|
+
|
|
3
|
+
const removeArgsFromHeaders = line => {
|
|
4
|
+
const words = line.split(' ')
|
|
5
|
+
if (words.length <= 3) return line
|
|
6
|
+
return `## ${words[1]} ${words[2]}\``
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const removeArgsFromLinks = line => {
|
|
10
|
+
const slug = line.substr(line.indexOf('#')+1, line.length-2)
|
|
11
|
+
const words = slug.split('-')
|
|
12
|
+
if (words.length <= 2) return line
|
|
13
|
+
return line.replace(slug, `${words[0]}-${words[1]})`)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const main = () => {
|
|
17
|
+
const outputBuffer = []
|
|
18
|
+
try {
|
|
19
|
+
const data = fs.readFileSync('README.md', 'utf8')
|
|
20
|
+
const lineBuffer = data.split('\n')
|
|
21
|
+
|
|
22
|
+
lineBuffer.forEach(line => {
|
|
23
|
+
if (line.startsWith('* [`swaggerhub')) return outputBuffer.push(removeArgsFromLinks(line))
|
|
24
|
+
if (line.startsWith('## `swaggerhub')) return outputBuffer.push(removeArgsFromHeaders(line))
|
|
25
|
+
return outputBuffer.push(line)
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
const output = outputBuffer.join('\n')
|
|
29
|
+
fs.writeFileSync('README.md', output)
|
|
30
|
+
|
|
31
|
+
} catch (err) {
|
|
32
|
+
console.error(err)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (require.main === module) {
|
|
37
|
+
main()
|
|
38
|
+
}
|
package/src/help.js
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const { getSpec, postSpec, deleteSpec, putSpec } = require('./spec')
|
|
2
|
+
|
|
3
|
+
const getProject = (pathParams, queryParams, accept = 'json') =>
|
|
4
|
+
getSpec('projects', pathParams, queryParams, accept)
|
|
5
|
+
|
|
6
|
+
const postProject = ({ pathParams, queryParams, body }) =>
|
|
7
|
+
postSpec('projects', pathParams, queryParams, body)
|
|
8
|
+
|
|
9
|
+
const putProject = ({ pathParams, body }) =>
|
|
10
|
+
putSpec('projects', pathParams, body)
|
|
11
|
+
|
|
12
|
+
const deleteProject = pathParams =>
|
|
13
|
+
deleteSpec('projects', pathParams)
|
|
14
|
+
|
|
15
|
+
module.exports = {
|
|
16
|
+
getProject,
|
|
17
|
+
postProject,
|
|
18
|
+
putProject,
|
|
19
|
+
deleteProject
|
|
20
|
+
}
|
|
@@ -6,6 +6,7 @@ const { errorMsg } = require('../../template-strings')
|
|
|
6
6
|
const optionalVersionRegex = new RegExp(/^\/?[\w\-.]+\/[\w\-.]+(\/[\w\-.]+)?(\/?)$/)
|
|
7
7
|
const requiredVersionRegex = new RegExp(/^\/?[\w\-.]+\/[\w\-.]+\/[\w\-.]+(\/?)$/)
|
|
8
8
|
const integrationIdentifierRegex = new RegExp(/^\/?[\w\-.]+\/[\w\-.]+\/[\w\-.]+\/[\w\-.]+(\/?)$/)
|
|
9
|
+
const projectIdentifierRegex = new RegExp(/^\/?[\w\-.]+\/[\w\-.]+$/)
|
|
9
10
|
|
|
10
11
|
const isValidIdentifier = (id, isVersionRequired) => isVersionRequired
|
|
11
12
|
? requiredVersionRegex.test(id)
|
|
@@ -42,6 +43,15 @@ const getIntegrationIdentifierArg = args => {
|
|
|
42
43
|
return identifier
|
|
43
44
|
}
|
|
44
45
|
|
|
46
|
+
const getProjectIdentifierArg = args => {
|
|
47
|
+
const format = 'OWNER/PROJECT_NAME'
|
|
48
|
+
const identifier = args[format]
|
|
49
|
+
if (!projectIdentifierRegex.test(identifier)) {
|
|
50
|
+
throw new CLIError(errorMsg.argsMustMatchFormat({ format }))
|
|
51
|
+
}
|
|
52
|
+
return identifier
|
|
53
|
+
}
|
|
54
|
+
|
|
45
55
|
const readConfigFile = filename => {
|
|
46
56
|
if (!existsSync(filename)) {
|
|
47
57
|
throw new CLIError(errorMsg.fileNotFound({ filename }))
|
|
@@ -60,6 +70,8 @@ const readConfigFile = filename => {
|
|
|
60
70
|
|
|
61
71
|
const splitPathParams = path => path.split('/').filter(Boolean)
|
|
62
72
|
|
|
73
|
+
const splitFlagParams = flag => flag.split(',').map(param => param.trim()).filter(Boolean)
|
|
74
|
+
|
|
63
75
|
const reqType = ({ json }) => json ? 'json' : 'yaml'
|
|
64
76
|
|
|
65
77
|
const resolvedParam = ({ resolved }) => resolved ? { resolved: true } : null
|
|
@@ -68,8 +80,10 @@ module.exports = {
|
|
|
68
80
|
getApiIdentifierArg,
|
|
69
81
|
getDomainIdentifierArg,
|
|
70
82
|
getIntegrationIdentifierArg,
|
|
83
|
+
getProjectIdentifierArg,
|
|
71
84
|
readConfigFile,
|
|
72
85
|
splitPathParams,
|
|
86
|
+
splitFlagParams,
|
|
73
87
|
reqType,
|
|
74
88
|
resolvedParam,
|
|
75
89
|
isValidIdentifier
|
|
@@ -43,7 +43,22 @@ const infoMsg = {
|
|
|
43
43
|
|
|
44
44
|
IntegrationUpdate: 'Updated integration \'{{integrationId}}\' on API \'{{apiPath}}\'',
|
|
45
45
|
|
|
46
|
-
Configure: 'Saved config to {{configFilePath}}'
|
|
46
|
+
Configure: 'Saved config to {{configFilePath}}',
|
|
47
|
+
|
|
48
|
+
ProjectCreate: 'Created project \'{{owner}}/{{projectName}}\'',
|
|
49
|
+
|
|
50
|
+
ProjectUpdate: 'Updated project \'{{owner}}/{{projectName}}\'',
|
|
51
|
+
|
|
52
|
+
ProjectApiAdd: 'Added api \'{{apiName}}\' to project \'{{projectPath}}\'',
|
|
53
|
+
|
|
54
|
+
ProjectApiRemove: 'Removed api \'{{apiName}}\' from project \'{{projectPath}}\'',
|
|
55
|
+
|
|
56
|
+
ProjectDomainAdd: 'Added domain \'{{domainName}}\' to project \'{{projectPath}}\'',
|
|
57
|
+
|
|
58
|
+
ProjectDomainRemove: 'Removed domain \'{{domainName}}\' from project \'{{projectPath}}\'',
|
|
59
|
+
|
|
60
|
+
ProjectDelete: 'Deleted project \'{{projectPath}}\''
|
|
61
|
+
|
|
47
62
|
}
|
|
48
63
|
|
|
49
64
|
module.exports = wrapTemplates({
|