-
Notifications
You must be signed in to change notification settings - Fork 14
/
create.js
78 lines (68 loc) · 2.67 KB
/
create.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
const { Flags, Args } = require('@oclif/core')
const { postProject } = require('../../requests/project')
const {
getProjectIdentifierArg,
splitPathParams,
splitFlagParams
} = require('../../support/command/parse-input')
const BaseCommand = require('../../support/command/base-command')
class CreateProjectCommand extends BaseCommand {
async run() {
const { args, flags } = await this.parse(CreateProjectCommand)
const projectPath = getProjectIdentifierArg(args)
const [owner, name] = splitPathParams(projectPath)
const body = {
owner,
name
}
// Append optional flags to body if present
if (flags.description !== undefined) body.description = flags.description
if (flags.apis !== undefined) body.apis = splitFlagParams(flags.apis)
if (flags.domains !== undefined) body.domains = splitFlagParams(flags.domains)
await this.createProject(owner, name, JSON.stringify(body))
}
async createProject(owner, projectName, body) {
const createRequest = {
pathParams: [owner],
body
}
return this.executeHttp({
execute: () => postProject(createRequest),
onResolve: this.logCommandSuccess({ owner, projectName }),
options: {}
})
}
}
CreateProjectCommand.description = 'Creates a new project in SwaggerHub.'
CreateProjectCommand.examples = [
'swaggerhub project:create organization/new_project_name --description "project description"',
'swaggerhub project:create organization/new_project_name -a "testapi1,testapi2"',
'swaggerhub project:create organization/new_project_name --apis "testapi1,testapi2"',
'swaggerhub project:create organization/new_project_name -d "testdomain3,testdomain4"',
'swaggerhub project:create organization/new_project_name --domains "testdomain3,testdomain4"',
'swaggerhub project:create organization/new_project_name -a "testapi1" -d "testdomain3" --description "description"'
]
CreateProjectCommand.args = {
'OWNER/PROJECT_NAME': Args.string({
required: true,
description: 'The new project to create on Swaggerhub'
})
}
CreateProjectCommand.flags = {
description: Flags.string({
description: 'Description of project',
required: false
}),
apis: Flags.string({
char: 'a',
description: 'Comma separated list of api names to include in project',
required: false
}),
domains: Flags.string({
char: 'd',
description: 'Comma separated list of domain names to include in project',
required: false
}),
...BaseCommand.flags
}
module.exports = CreateProjectCommand