UNPKG

1.03 kBJavaScriptView Raw
1'use strict';
2
3// local modules
4
5const create = require('../lib/create');
6
7// this module
8
9const INTERACTION = 'interaction';
10const RESOURCE_TYPES = [ INTERACTION ];
11const INTERACTION_MADL = 'madl';
12const DEFAULT_INTERACTION_TYPE = INTERACTION_MADL;
13const INTERACTION_TYPES = [ INTERACTION_MADL, 'message' ];
14
15module.exports = function (input, flags, options) {
16 const resourceType = input[0];
17 const name = input[1];
18
19 if (!~RESOURCE_TYPES.indexOf(resourceType)) {
20 console.error(`provide a supported resource: ${RESOURCE_TYPES.join(', ')}`);
21 process.exit(1);
22 }
23
24 let subType;
25
26 if (resourceType === INTERACTION) {
27 subType = flags.type || DEFAULT_INTERACTION_TYPE;
28 if (!~INTERACTION_TYPES.indexOf(subType)) {
29 console.error(`provide a supported "type": ${INTERACTION_TYPES.join(', ')}`);
30 process.exit(1);
31 }
32 }
33
34 if (!name) {
35 console.error('mandatory "name" not provided');
36 process.exit(1);
37 }
38
39 create.newInteraction({
40 name,
41 remote: flags.remote,
42 type: subType
43 });
44};