@@ -2,9 +2,8 @@ const _ = require('lodash');
2
2
const CFError = require ( 'cf-errors' ) ;
3
3
const Command = require ( '../../Command' ) ;
4
4
const { crudFilenameOption } = require ( '../../helpers/general' ) ;
5
+ const creatingEntities = require ( '../../helpers/creatingEntities' ) ;
5
6
const yargs = require ( 'yargs' ) ;
6
- const { validatePipelineSpec, checkOrProjectExists } = require ( '../../helpers/validation' ) ;
7
- const { sdk } = require ( '../../../../logic' ) ;
8
7
9
8
const get = new Command ( {
10
9
root : true ,
@@ -35,32 +34,14 @@ const get = new Command({
35
34
throw new CFError ( 'Name is missing' ) ;
36
35
}
37
36
38
- switch ( entity ) {
39
- case 'context' :
40
- await sdk . contexts . create ( data ) ;
41
- console . log ( `Context: ${ name } created` ) ;
42
- break ;
43
- case 'pipeline' :
44
- const result = await validatePipelineSpec ( data ) ;
45
- if ( ! result . valid ) {
46
- console . warn ( result . message ) ;
47
- return ;
48
- }
49
- await sdk . pipelines . create ( data ) ;
50
- console . log ( `Pipeline '${ name } ' created` ) ;
51
- break ;
52
- case 'step-type' :
53
- await sdk . steps . create ( data ) ;
54
- console . log ( `Step-type '${ name } ' created` ) ;
55
- break ;
56
- case 'project' :
57
- await checkOrProjectExists ( name ) ;
58
- await sdk . projects . create ( { projectName : name , ..._ . pick ( data . metadata , [ 'tags' , 'variables' ] ) } ) ;
59
- console . log ( `Project: ${ name } created` ) ;
60
- break ;
61
- default :
62
- throw new CFError ( `Entity: ${ entity } not supported` ) ;
37
+ const entities = creatingEntities ( { name, data } ) ;
38
+
39
+ if ( ! entities [ entity ] ) {
40
+ throw new CFError ( `Entity: ${ entity } not supported` ) ;
63
41
}
42
+
43
+ await entities [ entity ] ( ) ;
44
+ console . log ( `${ _ . capitalize ( entity ) } : ${ name } created` ) ;
64
45
} ,
65
46
} ) ;
66
47
0 commit comments