swaggerhub-cli 0.2.15 → 0.6.0

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.
Files changed (41) hide show
  1. package/README.md +498 -64
  2. package/oclif.manifest.json +1 -1
  3. package/package.json +28 -20
  4. package/src/commands/api/create.js +7 -6
  5. package/src/commands/api/delete.js +63 -0
  6. package/src/commands/api/publish.js +1 -1
  7. package/src/commands/api/unpublish.js +5 -13
  8. package/src/commands/api/update.js +21 -41
  9. package/src/commands/domain/create.js +5 -4
  10. package/src/commands/domain/delete.js +63 -0
  11. package/src/commands/domain/publish.js +1 -1
  12. package/src/commands/domain/setdefault.js +30 -0
  13. package/src/commands/domain/unpublish.js +4 -12
  14. package/src/commands/domain/update.js +109 -0
  15. package/src/commands/integration/create.js +3 -25
  16. package/src/commands/integration/delete.js +40 -0
  17. package/src/commands/integration/execute.js +40 -0
  18. package/src/commands/integration/get.js +51 -0
  19. package/src/commands/integration/list.js +62 -0
  20. package/src/commands/integration/update.js +51 -0
  21. package/src/commands/project/api/add.js +48 -0
  22. package/src/commands/project/api/remove.js +69 -0
  23. package/src/commands/project/create.js +77 -0
  24. package/src/commands/project/delete.js +44 -0
  25. package/src/commands/project/domain/add.js +48 -0
  26. package/src/commands/project/domain/remove.js +69 -0
  27. package/src/commands/project/get.js +51 -0
  28. package/src/commands/project/list.js +62 -0
  29. package/src/commands/project/member/list.js +60 -0
  30. package/src/config/index.js +4 -2
  31. package/src/format-readme.js +38 -0
  32. package/src/help.js +1 -1
  33. package/src/requests/api.js +5 -3
  34. package/src/requests/domain.js +4 -4
  35. package/src/requests/project.js +20 -0
  36. package/src/requests/spec.js +12 -0
  37. package/src/support/command/parse-input.js +44 -0
  38. package/src/support/command/update-command.js +21 -3
  39. package/src/template-strings/errors.js +1 -1
  40. package/src/template-strings/info.js +38 -3
  41. package/src/utils/oas.js +3 -3
@@ -0,0 +1,109 @@
1
+ const { flags } = require('@oclif/command')
2
+ const { readFileSync } = require('fs-extra')
3
+ const { getDomain, postDomain } = require('../../requests/domain')
4
+ const { getDomainIdentifierArg, splitPathParams } = require('../../support/command/parse-input')
5
+ const { getVersion, parseDefinition } = require('../../utils/oas')
6
+ const BaseCommand = require('../../support/command/base-command')
7
+ const UpdateCommand = require('../../support/command/update-command')
8
+
9
+ class UpdateDomainCommand extends UpdateCommand {
10
+
11
+ async updateDomain(owner, name, version, flags) {
12
+ const queryParams = { version }
13
+
14
+ if (flags.visibility) {
15
+ queryParams['isPrivate'] = flags.visibility !== 'public'
16
+ this.logCommandSuccess = this.setSuccessMessage('DomainUpdateVisibility')
17
+ }
18
+
19
+ const updateDomainObj = {
20
+ pathParams: [owner, name],
21
+ queryParams,
22
+ body: readFileSync(flags.file)
23
+ }
24
+
25
+ return await this.executeHttp({
26
+ execute: () => postDomain(updateDomainObj),
27
+ onResolve: this.logCommandSuccess({ owner, name, version, visibility: flags.visibility }),
28
+ options: { resolveStatus: [403] }
29
+ })
30
+ }
31
+
32
+ async run() {
33
+ const { args, flags } = this.parse(UpdateDomainCommand)
34
+
35
+ if (!Object.keys(flags).length) {
36
+ return this.error('No updates specified', { exit: 1 })
37
+ }
38
+
39
+ const definition = flags.file ? parseDefinition(flags.file) : null
40
+ const domainPath = getDomainIdentifierArg(args)
41
+ const [owner, name, version] = splitPathParams(domainPath)
42
+ const defaultVersion = definition ? getVersion(definition) : await this.getDefaultDomainVersion([owner, name])
43
+ const domainVersion = version ? version : defaultVersion
44
+ const type = 'domains'
45
+
46
+ if (flags.file) {
47
+ await this.handleUpdate(owner, name, domainVersion, flags)
48
+ } else if (flags.visibility) {
49
+ await this.updateVisibility(type, owner, name, domainVersion, flags.visibility !== 'public')
50
+ }
51
+
52
+ if (flags.published) await this.updatePublish(type, owner, name, domainVersion, flags.published === 'publish')
53
+ if (flags.setdefault) await this.updateDefault(type, owner, name, domainVersion)
54
+ }
55
+
56
+ async handleUpdate(owner, name, version, flags) {
57
+ await this.executeHttp({
58
+ execute: () => getDomain([owner, name, version]),
59
+ onResolve: () => this.updateDomain(owner, name, version, flags),
60
+ options: { resolveStatus: [403] }
61
+ })
62
+ }
63
+ }
64
+
65
+ UpdateDomainCommand.description = `update a domain
66
+ The domain version from the file will be used unless the version is specified in the command argument.
67
+ When no file is specified then the default domain version will be updated.
68
+ The domain visibility can be changed by using visibility flag.
69
+ `
70
+
71
+ UpdateDomainCommand.examples = [
72
+ 'swaggerhub domain:update organization/domain --file domain.yaml',
73
+ 'swaggerhub domain:update organization/domain/1.0.0 --file domain.json',
74
+ 'swaggerhub domain:update organization/domain/1.0.0 --published=publish --file domain.json',
75
+ 'swaggerhub domain:update organization/domain/1.0.0 --setdefault --file domain.json',
76
+ 'swaggerhub domain:update organization/domain/1.0.0 --published=unpublish --setdefault --file domain.json',
77
+ 'swaggerhub domain:update organization/domain/1.0.0 --visibility=private',
78
+ ]
79
+
80
+ UpdateDomainCommand.args = [{
81
+ name: 'OWNER/DOMAIN_NAME/[VERSION]',
82
+ required: true,
83
+ description: 'domain to update in SwaggerHub'
84
+ }]
85
+
86
+ UpdateDomainCommand.flags = {
87
+ file: flags.string({
88
+ char: 'f',
89
+ description: 'file location of domain to update',
90
+ required: false,
91
+ multiple: false
92
+ }),
93
+ visibility: flags.string({
94
+ description: 'visibility of domain in SwaggerHub',
95
+ options: ['public', 'private']
96
+ }),
97
+ published: flags.string({
98
+ description: 'sets the lifecycle setting of the domain version',
99
+ options: ['publish', 'unpublish'],
100
+ required: false
101
+ }),
102
+ setdefault: flags.boolean({
103
+ description: 'sets domain version to be the default',
104
+ required: false
105
+ }),
106
+ ...BaseCommand.flags
107
+ }
108
+
109
+ module.exports = UpdateDomainCommand
@@ -1,42 +1,20 @@
1
1
  const { flags } = require('@oclif/command')
2
- const { existsSync, readFileSync } = require('fs-extra')
3
- const { hasJsonStructure } = require('../../utils/general')
4
2
  const { postApi } = require('../../requests/api')
5
- const { getApiIdentifierArg } = require('../../support/command/parse-input')
3
+ const { getApiIdentifierArg, readConfigFile } = require('../../support/command/parse-input')
6
4
  const BaseCommand = require('../../support/command/base-command')
7
- const { CLIError } = require('@oclif/errors')
8
- const { errorMsg } = require('../../template-strings')
9
5
 
10
6
  class CreateIntegrationCommand extends BaseCommand {
11
7
 
12
8
  async run() {
13
9
  const { args, flags } = this.parse(CreateIntegrationCommand)
14
- const config = this.readConfigFile(flags.file)
10
+ const config = readConfigFile(flags.file)
15
11
 
16
12
  const requestedApiPath = getApiIdentifierArg(args)
17
13
  const apiPath = await this.ensureVersion(requestedApiPath)
18
14
  await this.createIntegration(apiPath, config)
19
15
  }
20
16
 
21
- readConfigFile(filename) {
22
-
23
- if (!existsSync(filename)) {
24
- throw new CLIError(errorMsg.fileNotFound({ filename }))
25
- }
26
-
27
- const config = readFileSync(filename)
28
- if (config.length === 0) {
29
- throw new CLIError(errorMsg.fileIsEmpty({ filename }))
30
- }
31
-
32
- if (!hasJsonStructure(config)) {
33
- throw new CLIError(errorMsg.invalidConfig())
34
- }
35
- return config
36
- }
37
-
38
17
  async createIntegration(apiPath, config) {
39
-
40
18
  const createRequest = {
41
19
  pathParams: [apiPath, 'integrations'],
42
20
  body: config
@@ -50,7 +28,7 @@ class CreateIntegrationCommand extends BaseCommand {
50
28
  }
51
29
  }
52
30
 
53
- CreateIntegrationCommand.description = `creates a new API integation from a JSON configuration file.
31
+ CreateIntegrationCommand.description = `creates a new API integration from a JSON configuration file.
54
32
  See the documentation for configuration files: https://github.com/SmartBear/swaggerhub-cli/tree/master/examples/integrations
55
33
  When VERSION is not included in the argument, the integration will be added to be default API version.
56
34
  `
@@ -0,0 +1,40 @@
1
+ const { deleteApi } = require('../../requests/api')
2
+ const { getIntegrationIdentifierArg, splitPathParams } = require('../../support/command/parse-input')
3
+ const BaseCommand = require('../../support/command/base-command')
4
+
5
+ class DeleteIntegrationCommand extends BaseCommand {
6
+
7
+ async run() {
8
+ const { args } = this.parse(DeleteIntegrationCommand)
9
+ const integrationPath = getIntegrationIdentifierArg(args)
10
+ await this.deleteIntegration(integrationPath)
11
+ }
12
+
13
+ async deleteIntegration(integrationPath) {
14
+ const [owner, api, version, integrationId] = splitPathParams(integrationPath)
15
+
16
+ return this.executeHttp({
17
+ execute: () => deleteApi([owner, api, version, 'integrations', integrationId]),
18
+ onResolve: this.logCommandSuccess({ integrationId, apiPath: [owner, api, version].join('/') }),
19
+ options: {}
20
+ })
21
+ }
22
+ }
23
+
24
+ DeleteIntegrationCommand.description = 'deletes the integration from the given API.'
25
+
26
+ DeleteIntegrationCommand.examples = [
27
+ 'swaggerhub integration:delete organization/api/1.0.0/503c2db6-448a-4678-a310-f465429e9704'
28
+ ]
29
+
30
+ DeleteIntegrationCommand.args = [{
31
+ name: 'OWNER/API_NAME/VERSION/INTEGRATION_ID',
32
+ required: true,
33
+ description: 'Integration to delete'
34
+ }]
35
+
36
+ DeleteIntegrationCommand.flags = {
37
+ ...BaseCommand.flags
38
+ }
39
+
40
+ module.exports = DeleteIntegrationCommand
@@ -0,0 +1,40 @@
1
+ const { postApi } = require('../../requests/api')
2
+ const { getIntegrationIdentifierArg, splitPathParams } = require('../../support/command/parse-input')
3
+ const BaseCommand = require('../../support/command/base-command')
4
+
5
+ class ExecuteIntegrationCommand extends BaseCommand {
6
+
7
+ async run() {
8
+ const { args } = this.parse(ExecuteIntegrationCommand)
9
+ const integrationPath = getIntegrationIdentifierArg(args)
10
+ await this.executeIntegration(integrationPath)
11
+ }
12
+
13
+ async executeIntegration(integrationPath) {
14
+ const [owner, api, version, integrationId] = splitPathParams(integrationPath)
15
+
16
+ return this.executeHttp({
17
+ execute: () => postApi({ pathParams: [owner, api, version, 'integrations', integrationId, 'execute'] }),
18
+ onResolve: this.logCommandSuccess({ integrationId, apiPath: `${owner}/${api}/${version}` }),
19
+ options: {}
20
+ })
21
+ }
22
+ }
23
+
24
+ ExecuteIntegrationCommand.description = 'executes an integration for the given API.'
25
+
26
+ ExecuteIntegrationCommand.examples = [
27
+ 'swaggerhub integration:execute organization/api/1.0.0/503c2db6-448a-4678-a310-f465429e9704'
28
+ ]
29
+
30
+ ExecuteIntegrationCommand.args = [{
31
+ name: 'OWNER/API_NAME/VERSION/INTEGRATION_ID',
32
+ required: true,
33
+ description: 'Integration to execute for given API'
34
+ }]
35
+
36
+ ExecuteIntegrationCommand.flags = {
37
+ ...BaseCommand.flags
38
+ }
39
+
40
+ module.exports = ExecuteIntegrationCommand
@@ -0,0 +1,51 @@
1
+ const { getApi } = require('../../requests/api')
2
+ const { getIntegrationIdentifierArg, splitPathParams } = require('../../support/command/parse-input')
3
+ const { getResponseContent } = require('../../support/command/handle-response')
4
+ const { prettyPrintJSON } = require('../../utils/general')
5
+ const BaseCommand = require('../../support/command/base-command')
6
+
7
+ class GetIntegrationCommand extends BaseCommand {
8
+ constructor(...props) {
9
+ super(...props)
10
+ this.logIntegration = this.logIntegration.bind(this)
11
+ }
12
+
13
+ async run() {
14
+ const { args } = this.parse(GetIntegrationCommand)
15
+ const integrationPath = getIntegrationIdentifierArg(args)
16
+ await this.getIntegration(integrationPath)
17
+ }
18
+
19
+ async logIntegration(response) {
20
+ const integration = await getResponseContent(response)
21
+ this.log(prettyPrintJSON(integration))
22
+ }
23
+
24
+ async getIntegration(integrationPath) {
25
+ const [owner, api, version, integrationId] = splitPathParams(integrationPath)
26
+
27
+ return this.executeHttp({
28
+ execute: () => getApi([owner, api, version, 'integrations', integrationId]),
29
+ onResolve: this.logIntegration,
30
+ options: {}
31
+ })
32
+ }
33
+ }
34
+
35
+ GetIntegrationCommand.description = 'retieves an integration for the given API.'
36
+
37
+ GetIntegrationCommand.examples = [
38
+ 'swaggerhub integration:get organization/api/1.0.0/503c2db6-448a-4678-a310-f465429e9704'
39
+ ]
40
+
41
+ GetIntegrationCommand.args = [{
42
+ name: 'OWNER/API_NAME/VERSION/INTEGRATION_ID',
43
+ required: true,
44
+ description: 'Integration to fetch for given API'
45
+ }]
46
+
47
+ GetIntegrationCommand.flags = {
48
+ ...BaseCommand.flags
49
+ }
50
+
51
+ module.exports = GetIntegrationCommand
@@ -0,0 +1,62 @@
1
+ const { cli } = require('cli-ux')
2
+ const { getApi } = require('../../requests/api')
3
+ const { getResponseContent } = require('../../support/command/handle-response')
4
+ const { getApiIdentifierArg } = require('../../support/command/parse-input')
5
+ const BaseCommand = require('../../support/command/base-command')
6
+
7
+ class ListIntegrationCommand extends BaseCommand {
8
+ constructor(...props) {
9
+ super(...props)
10
+ this.logIntegration = this.logIntegration.bind(this)
11
+ }
12
+
13
+ async run() {
14
+ const { args } = this.parse(ListIntegrationCommand)
15
+ const requestedApiPath = getApiIdentifierArg(args)
16
+ const apiPath = await this.ensureVersion(requestedApiPath)
17
+ await this.listIntegrations(apiPath)
18
+ }
19
+
20
+ async logIntegration(response) {
21
+ const responseObj = JSON.parse(await getResponseContent(response))
22
+ cli.table(responseObj.integrations, {
23
+ id: {
24
+ header: 'ID',
25
+ minWidth: 38
26
+ },
27
+ name: {},
28
+ configType: {
29
+ header: 'Type'
30
+ },
31
+ enabled: {}
32
+ }, {
33
+ printLine: this.log
34
+ })
35
+ }
36
+
37
+ async listIntegrations(apiPath) {
38
+ return this.executeHttp({
39
+ execute: () => getApi([apiPath, 'integrations']),
40
+ onResolve: this.logIntegration,
41
+ options: {}
42
+ })
43
+ }
44
+ }
45
+
46
+ ListIntegrationCommand.description = 'list integrations on an API.'
47
+
48
+ ListIntegrationCommand.examples = [
49
+ 'swaggerhub integration:list organization/api/1.0.0'
50
+ ]
51
+
52
+ ListIntegrationCommand.args = [{
53
+ name: 'OWNER/API_NAME/[VERSION]',
54
+ required: true,
55
+ description: 'API to list integrations on'
56
+ }]
57
+
58
+ ListIntegrationCommand.flags = {
59
+ ...BaseCommand.flags
60
+ }
61
+
62
+ module.exports = ListIntegrationCommand
@@ -0,0 +1,51 @@
1
+ const { flags } = require('@oclif/command')
2
+ const { putApi } = require('../../requests/api')
3
+ const { getIntegrationIdentifierArg, readConfigFile, splitPathParams } = require('../../support/command/parse-input')
4
+ const BaseCommand = require('../../support/command/base-command')
5
+
6
+ class UpdateIntegrationCommand extends BaseCommand {
7
+
8
+ async run() {
9
+ const { args, flags } = this.parse(UpdateIntegrationCommand)
10
+ const integrationPath = getIntegrationIdentifierArg(args)
11
+ const config = readConfigFile(flags.file)
12
+ await this.updateIntegration(integrationPath, config)
13
+ }
14
+
15
+ async updateIntegration(integrationPath, config) {
16
+ const [owner, api, version, integrationId] = splitPathParams(integrationPath)
17
+ const updateRequest = {
18
+ pathParams: [owner, api, version, 'integrations', integrationId],
19
+ body: config
20
+ }
21
+
22
+ return this.executeHttp({
23
+ execute: () => putApi(updateRequest),
24
+ onResolve: this.logCommandSuccess({ integrationId, apiPath: `${owner}/${api}/${version}` }),
25
+ options: {}
26
+ })
27
+ }
28
+ }
29
+
30
+ UpdateIntegrationCommand.description = 'update the configuration of an API integration.'
31
+
32
+ UpdateIntegrationCommand.examples = [
33
+ 'swaggerhub integration:update organization/api/1.0.0/503c2db6-448a-4678-abcd-0123456789abc --file config.json'
34
+ ]
35
+
36
+ UpdateIntegrationCommand.args = [{
37
+ name: 'OWNER/API_NAME/VERSION/INTEGRATION_ID',
38
+ required: true,
39
+ description: 'Integration to update on the given API'
40
+ }]
41
+
42
+ UpdateIntegrationCommand.flags = {
43
+ file: flags.string({
44
+ char: 'f',
45
+ description: 'location of integration configuration file',
46
+ required: true
47
+ }),
48
+ ...BaseCommand.flags
49
+ }
50
+
51
+ module.exports = UpdateIntegrationCommand
@@ -0,0 +1,48 @@
1
+ const { putProject } = require('../../../requests/project')
2
+ const {
3
+ getProjectIdentifierArg
4
+ } = require('../../../support/command/parse-input')
5
+ const BaseCommand = require('../../../support/command/base-command')
6
+
7
+ class ProjectApiAddCommand extends BaseCommand {
8
+
9
+ async run() {
10
+ const { args } = this.parse(ProjectApiAddCommand)
11
+ const projectPath = getProjectIdentifierArg(args)
12
+ const apiName = args['API']
13
+
14
+ await this.addApiToProject(projectPath, apiName)
15
+ }
16
+
17
+ async addApiToProject(projectPath, apiName) {
18
+
19
+ return this.executeHttp({
20
+ execute: () => putProject({ pathParams: [projectPath, 'apis', apiName] }),
21
+ onResolve: this.logCommandSuccess({ apiName, projectPath }),
22
+ options: {}
23
+ })
24
+ }
25
+ }
26
+
27
+ ProjectApiAddCommand.description = 'Adds an API to an existing project.'
28
+
29
+
30
+ ProjectApiAddCommand.examples = [
31
+ 'swaggerhub project:api:add organization/project_name my_api'
32
+ ]
33
+
34
+ ProjectApiAddCommand.args = [
35
+ {
36
+ name: 'OWNER/PROJECT_NAME',
37
+ required: true,
38
+ description: 'The project to add the API to'
39
+ },
40
+
41
+ {
42
+ name: 'API',
43
+ required: true,
44
+ description: 'The name of the API to add'
45
+ }
46
+ ]
47
+
48
+ module.exports = ProjectApiAddCommand
@@ -0,0 +1,69 @@
1
+ const { putProject, getProject } = require('../../../requests/project')
2
+ const {
3
+ getProjectIdentifierArg,
4
+ splitPathParams,
5
+ } = require('../../../support/command/parse-input')
6
+ const BaseCommand = require('../../../support/command/base-command')
7
+ const { getResponseContent } = require('../../../support/command/handle-response')
8
+ const { pipeAsync } = require('../../../utils/general')
9
+
10
+ class ProjectApiRemoveCommand extends BaseCommand {
11
+
12
+ async run() {
13
+ const { args } = this.parse(ProjectApiRemoveCommand)
14
+ const projectPath = getProjectIdentifierArg(args)
15
+ const apiToRemove = args['API']
16
+
17
+ await this.removeApiFromProject(projectPath, apiToRemove)
18
+ }
19
+
20
+ async getProjectDetails(owner, projectName) {
21
+ return this.executeHttp({
22
+ execute: () => getProject([owner, projectName]),
23
+ onResolve: pipeAsync(getResponseContent, JSON.parse),
24
+ options: {}
25
+ })
26
+ }
27
+
28
+ async removeApiFromProject(projectPath, apiName) {
29
+ const [owner, projectName] = splitPathParams(projectPath)
30
+
31
+ const project = await this.getProjectDetails(owner, projectName)
32
+ if (project.apis && !project.apis.includes(apiName)) {
33
+ return this.log(`Api \'${apiName}\' does not exist in project \'${projectPath}\'`)
34
+ }
35
+
36
+ project.apis = project.apis.filter(item => item !== apiName)
37
+ const updateRequest = {
38
+ pathParams: [owner, projectName],
39
+ body: JSON.stringify(project)
40
+ }
41
+
42
+ return this.executeHttp({
43
+ execute: () => putProject(updateRequest),
44
+ onResolve: this.logCommandSuccess({ apiName, projectPath }),
45
+ options: {}
46
+ })
47
+ }
48
+ }
49
+
50
+ ProjectApiRemoveCommand.description = 'Removes an API from a project in SwaggerHub.'
51
+
52
+ ProjectApiRemoveCommand.examples = [
53
+ 'swaggerhub project:api:remove organization/project_name my_api',
54
+ ]
55
+
56
+ ProjectApiRemoveCommand.args = [
57
+ {
58
+ name: 'OWNER/PROJECT_NAME',
59
+ required: true,
60
+ description: 'The project remove the API from'
61
+ },
62
+ {
63
+ name: 'API',
64
+ required: true,
65
+ description: 'The API to remove'
66
+ }
67
+ ]
68
+
69
+ module.exports = ProjectApiRemoveCommand
@@ -0,0 +1,77 @@
1
+ const { flags } = require('@oclif/command')
2
+ const { postProject } = require('../../requests/project')
3
+ const {
4
+ getProjectIdentifierArg,
5
+ splitPathParams,
6
+ splitFlagParams
7
+ } = require('../../support/command/parse-input')
8
+ const BaseCommand = require('../../support/command/base-command')
9
+
10
+ class CreateProjectCommand extends BaseCommand {
11
+
12
+ async run() {
13
+ const { args, flags } = this.parse(CreateProjectCommand)
14
+ const projectPath = getProjectIdentifierArg(args)
15
+ const [owner, name] = splitPathParams(projectPath)
16
+ const body = {
17
+ owner,
18
+ name
19
+ }
20
+ // Append optional flags to body if present
21
+ if (flags.description !== undefined) body.description = flags.description
22
+ if (flags.apis !== undefined) body.apis = splitFlagParams(flags.apis)
23
+ if (flags.domains !== undefined) body.domains = splitFlagParams(flags.domains)
24
+
25
+ await this.createProject(owner, name, JSON.stringify(body))
26
+ }
27
+
28
+ async createProject(owner, projectName, body) {
29
+ const createRequest = {
30
+ pathParams: [owner],
31
+ body
32
+ }
33
+
34
+ return this.executeHttp({
35
+ execute: () => postProject(createRequest),
36
+ onResolve: this.logCommandSuccess({ owner, projectName }),
37
+ options: {}
38
+ })
39
+ }
40
+ }
41
+
42
+ CreateProjectCommand.description = 'Creates a new project in SwaggerHub.'
43
+
44
+ CreateProjectCommand.examples = [
45
+ 'swaggerhub project:create organization/new_project_name --description "project description"',
46
+ 'swaggerhub project:create organization/new_project_name -a "testapi1,testapi2"',
47
+ 'swaggerhub project:create organization/new_project_name --apis "testapi1,testapi2"',
48
+ 'swaggerhub project:create organization/new_project_name -d "testdomain3,testdomain4"',
49
+ 'swaggerhub project:create organization/new_project_name --domains "testdomain3,testdomain4"',
50
+ 'swaggerhub project:create organization/new_project_name -a "testapi1" -d "testdomain3" --description "description"'
51
+ ]
52
+
53
+ CreateProjectCommand.args = [{
54
+ name: 'OWNER/PROJECT_NAME',
55
+ required: true,
56
+ description: 'The new project to create'
57
+ }]
58
+
59
+ CreateProjectCommand.flags = {
60
+ description: flags.string({
61
+ description: 'Description of project',
62
+ required: false
63
+ }),
64
+ apis: flags.string({
65
+ char: 'a',
66
+ description: 'Comma separated list of api names to include in project',
67
+ required: false
68
+ }),
69
+ domains: flags.string({
70
+ char: 'd',
71
+ description: 'Comma separated list of domain names to include in project',
72
+ required: false
73
+ }),
74
+ ...BaseCommand.flags
75
+ }
76
+
77
+ module.exports = CreateProjectCommand
@@ -0,0 +1,44 @@
1
+ const { deleteProject } = require('../../requests/project')
2
+ const { getProjectIdentifierArg, splitPathParams } = require('../../support/command/parse-input')
3
+ const BaseCommand = require('../../support/command/base-command')
4
+
5
+ class DeleteProjectCommand extends BaseCommand {
6
+ constructor(...props) {
7
+ super(...props)
8
+ this.setSuccessMessage('ProjectDelete')
9
+ }
10
+
11
+ async run() {
12
+ const { args } = this.parse(DeleteProjectCommand)
13
+ const projectPath = getProjectIdentifierArg(args)
14
+ await this.deleteProject(projectPath)
15
+ }
16
+
17
+ async deleteProject(projectPath) {
18
+ const [owner, projectName] = splitPathParams(projectPath)
19
+
20
+ return this.executeHttp({
21
+ execute: () => deleteProject([owner, projectName]),
22
+ onResolve: this.logCommandSuccess({ projectPath }),
23
+ options: {}
24
+ })
25
+ }
26
+ }
27
+
28
+ DeleteProjectCommand.description = 'Deletes a project from SwaggerHub.'
29
+
30
+ DeleteProjectCommand.examples = [
31
+ 'swaggerhub project:delete organization/project_name'
32
+ ]
33
+
34
+ DeleteProjectCommand.args = [{
35
+ name: 'OWNER/PROJECT_NAME',
36
+ required: true,
37
+ description: 'Project to delete'
38
+ }]
39
+
40
+ DeleteProjectCommand.flags = {
41
+ ...BaseCommand.flags
42
+ }
43
+
44
+ module.exports = DeleteProjectCommand