1
- const debug = require ( 'debug' ) ( 'codefresh:cli:create:context ' ) ;
1
+ const debug = require ( 'debug' ) ( 'codefresh:cli:create:pipelines2 ' ) ;
2
2
const Command = require ( '../../Command' ) ;
3
3
const CFError = require ( 'cf-errors' ) ;
4
4
const _ = require ( 'lodash' ) ;
5
- const { pipeline } = require ( '../../../../logic' ) . api ;
6
- const { specifyOutputForSingle, specifyOutputForArray } = require ( '../../helpers/get' ) ;
7
- const getRoot = require ( '../root/get.cmd' ) ;
8
5
const DEFAULTS = require ( '../../defaults' ) ;
6
+ const { pipeline } = require ( '../../../../logic' ) . api ;
7
+ const { prepareKeyValueFromCLIEnvOption, printError } = require ( '../../helpers/general' ) ;
8
+ const { specifyOutputForArray } = require ( '../../helpers/get' ) ;
9
9
10
+ const getRoot = require ( '../root/get.cmd' ) ;
10
11
11
12
12
13
const command = new Command ( {
13
14
command : 'pipelines [id..]' ,
14
15
aliases : [ 'pip' , 'pipeline' ] ,
15
16
parent : getRoot ,
16
17
description : 'Get a specific pipeline or an array of pipelines' ,
17
- usage : 'Passing [id] argument will cause a retrieval of a specific pipeline.\n In case of not passing [id] argument, a list will be returned' ,
18
18
webDocs : {
19
19
category : 'Pipelines' ,
20
20
title : 'Get Pipeline' ,
21
21
} ,
22
22
builder : ( yargs ) => {
23
23
return yargs
24
24
. positional ( 'id' , {
25
- describe : 'Pipeline id' ,
25
+ describe : 'Pipeline name/ id' ,
26
26
} )
27
- . option ( 'repo-owner' , {
28
- describe : 'Repository owner' ,
27
+ . option ( 'decrypt-variables' , {
28
+ alias : 'd' ,
29
+ describe : 'Will decrypt encrypted variables' ,
29
30
} )
30
- . option ( 'repo-name' , {
31
- describe : 'Repository name' ,
31
+ . option ( 'name' , {
32
+ describe : 'Filter pipelines by name' ,
33
+ } )
34
+ . option ( 'label' , {
35
+ describe : 'Filter by a label' ,
36
+ alias : 'l' ,
37
+ default : [ ] ,
32
38
} )
33
39
. option ( 'limit' , {
34
40
describe : 'Limit amount of returned results' ,
@@ -37,40 +43,43 @@ const command = new Command({
37
43
. option ( 'page' , {
38
44
describe : 'Paginated page' ,
39
45
default : DEFAULTS . GET_PAGINATED_PAGE ,
40
- } )
41
- . option ( 'name' , {
42
- describe : 'Filter results by pipeline name' ,
43
- type : Array ,
44
- } )
45
- . example ( 'codefresh get pipeline ID' , 'Get pipeline ID' )
46
- . example ( 'codefresh get pipelines' , 'Get all pipelines' )
47
- . example ( 'codefresh get pipelines --name release' , 'Get all pipelines that their name is release' )
48
- . example ( 'codefresh get pipelines --repo-name node' , "Get all pipelines that are associated with the repository name 'node'" ) ;
46
+ } ) ;
49
47
} ,
50
48
handler : async ( argv ) => {
51
- const pipelineIds = argv . id ;
52
- const repoOwner = argv [ 'repo-owner' ] ;
53
- const repoName = argv [ 'repo-name' ] ;
54
- const name = argv . name ;
49
+ const { id : ids , name, output, d : decryptVariables } = argv ;
55
50
const limit = argv . limit ;
56
- const page = argv . page ;
51
+ const offset = ( argv . page - 1 ) * limit ;
52
+ const labels = prepareKeyValueFromCLIEnvOption ( argv . label ) ;
53
+
54
+ debug ( `decrypt: ${ decryptVariables } ` ) ;
55
+ if ( ! _ . isEmpty ( ids ) ) {
56
+ const pipelines = [ ] ;
57
+ for ( const id of ids ) {
58
+ try {
59
+ const currPipeline = await pipeline . getPipelineByName ( id , { decryptVariables } ) ;
60
+ pipelines . push ( currPipeline ) ;
61
+ } catch ( err ) {
62
+ if ( pipelines . length ) {
63
+ specifyOutputForArray ( output , pipelines ) ;
64
+ }
57
65
58
- let pipelines = [ ] ;
59
- if ( ! _ . isEmpty ( pipelineIds ) ) {
60
- for ( const id of pipelineIds ) {
61
- const currPipeline = await pipeline . getPipelineById ( id ) ;
62
- pipelines . push ( currPipeline ) ;
66
+ debug ( err . toString ( ) ) ;
67
+ const message = err . toString ( ) . includes ( 'not find' ) ? `Pipeline '${ id } ' was not found.` : 'Error occurred' ;
68
+ throw new CFError ( {
69
+ cause : err ,
70
+ message,
71
+ } ) ;
72
+ }
63
73
}
74
+ specifyOutputForArray ( output , pipelines ) ;
64
75
} else {
65
- pipelines = await pipeline . getAll ( {
66
- repoOwner,
67
- repoName,
68
- name,
76
+ specifyOutputForArray ( output , await pipeline . getAll ( {
69
77
limit,
70
- page,
71
- } ) ;
78
+ offset,
79
+ name,
80
+ labels,
81
+ } ) ) ;
72
82
}
73
- specifyOutputForArray ( argv . output , pipelines ) ;
74
83
} ,
75
84
} ) ;
76
85
0 commit comments