UNPKG

1.21 kBJavaScriptView Raw
1'use strict'
2
3let allEndpoints = require('./endpoints.js').all
4let error = require('./error.js')
5
6module.exports = function * (context, heroku) {
7 if (context.flags.endpoint && context.flags.name) {
8 error.exit(1, 'Specified both --name and --endpoint, please use just one')
9 }
10
11 var endpoints = yield allEndpoints(context.app, heroku)
12
13 if (endpoints.length === 0) {
14 error.exit(1, `${context.app} has no SSL certificates`)
15 }
16
17 if (context.flags.endpoint) {
18 endpoints = endpoints.filter(function (endpoint) {
19 return endpoint.cname === context.flags.endpoint
20 })
21
22 if (endpoints.length > 1) {
23 error.exit(1, 'Must pass --name when more than one endpoint matches --endpoint')
24 }
25 }
26
27 if (context.flags.name) {
28 endpoints = endpoints.filter(function (endpoint) {
29 return endpoint.name === context.flags.name
30 })
31
32 if (endpoints.length > 1) {
33 error.exit(1, `More than one endpoint matches ${context.flags.name}, please file a support ticket`)
34 }
35 }
36
37 if (endpoints.length > 1) {
38 error.exit(1, 'Must pass --name when more than one endpoint')
39 }
40
41 if (endpoints.length === 0) {
42 error.exit(1, 'Record not found.')
43 }
44
45 return endpoints[0]
46}