1 | #!/usr/bin/env node
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 | var Catalogs = require('apiconnect-apim-client').catalogs;
|
16 | var apicUtil = require('apiconnect-cli-util').Util;
|
17 | var fmt = require('./formatter');
|
18 | var g = require('strong-globalize')();
|
19 |
|
20 | module.exports.catalogsList = catalogsList;
|
21 | function catalogsList(options) {
|
22 | if (options.allOrganizations) {
|
23 | options.organization = null;
|
24 | } else if (!options.organization) {
|
25 | throw new Error(g.f('The {{--organization}} option is required'));
|
26 | }
|
27 | var catalogsFun = options.allOrganizations ? Catalogs.listAll : Catalogs.list;
|
28 | return catalogsFun(options)
|
29 | .then(function(res) {
|
30 | fmt.listFormatter(res, options);
|
31 | })
|
32 | .catch(function(err) {
|
33 | fmt.error(err);
|
34 | });
|
35 | };
|
36 |
|
37 | module.exports.catalogsCreate = catalogsCreate;
|
38 | function catalogsCreate(displayName, options) {
|
39 | if (typeof options.name === 'function') {
|
40 | options.name = null;
|
41 | }
|
42 | options.name = options.name || apicUtil.generateSlugFromText(displayName);
|
43 | options.displayName = displayName;
|
44 | return Catalogs.create(options).then(function(result) {
|
45 | fmt.createFormatter(result, options);
|
46 | });
|
47 | }
|
48 |
|
49 | module.exports.catalogsGet = catalogsGet;
|
50 | function catalogsGet(name, options) {
|
51 | options.catalog = name;
|
52 | return Catalogs.get(options).then(function(result) {
|
53 | fmt.getFormatter(result, options);
|
54 | });
|
55 | }
|
56 |
|
57 | module.exports.catalogsDelete = catalogsDelete;
|
58 | function catalogsDelete(name, options) {
|
59 | options.catalog = name;
|
60 | return Catalogs.delete(options).then(function(result) {
|
61 | fmt.deleteFormatter(name, options);
|
62 | });
|
63 | }
|
64 |
|
65 | module.exports.catalogsSet = catalogsSet;
|
66 | function catalogsSet(name, options) {
|
67 | options.catalog = name;
|
68 | options.spaceEnabled = options.spaces && (options.spaces === 'enabled');
|
69 | return Catalogs.set(options).then(function(result) {
|
70 | fmt.setFormatter(result, options);
|
71 | });
|
72 | }
|
73 |
|
74 | module.exports.catalogsTransfer = catalogsTransfer;
|
75 | function catalogsTransfer(name, userId, options) {
|
76 | options.catalog = name;
|
77 | options.userId = userId;
|
78 | return Catalogs.transferOwner(options).then(function(result) {
|
79 | fmt.transferFormatter(name, options);
|
80 | })
|
81 | .catch(function(err) {
|
82 | fmt.error(err);
|
83 | });
|
84 | }
|