@@ -3,7 +3,7 @@ const Command = require('../../Command');
3
3
const CFError = require ( 'cf-errors' ) ;
4
4
const _ = require ( 'lodash' ) ;
5
5
const DEFAULTS = require ( '../../defaults' ) ;
6
- const { workflow } = require ( '../../../../logic' ) . api ;
6
+ const { workflow , pipeline } = require ( '../../../../logic' ) . api ;
7
7
const { specifyOutputForSingle, specifyOutputForArray } = require ( '../../helpers/get' ) ;
8
8
const getRoot = require ( '../root/get.cmd' ) ;
9
9
@@ -22,22 +22,63 @@ const command = new Command({
22
22
. option ( 'page' , {
23
23
describe : 'Paginated page' ,
24
24
default : DEFAULTS . GET_PAGINATED_PAGE ,
25
+ } )
26
+ . option ( 'status' , {
27
+ describe : 'Filter results by statuses' ,
28
+ type : Array ,
29
+ choices : [ 'error' , 'running' , 'success' , 'terminated' ] ,
30
+ } )
31
+ . option ( 'trigger' , {
32
+ describe : 'Filter results by triggers' ,
33
+ type : Array ,
34
+ choices : [ 'build' , 'launch' ] ,
35
+ } )
36
+ . option ( 'pipeline-id' , {
37
+ describe : 'Filter results by pipeline id' ,
38
+ type : Array ,
39
+ default : [ ] ,
40
+ } )
41
+ . option ( 'pipeline-name' , {
42
+ describe : 'Filter results by pipeline name' ,
43
+ type : Array ,
44
+ default : [ ] ,
25
45
} ) ;
46
+
26
47
} ,
27
48
handler : async ( argv ) => {
28
49
const workflowId = argv . id ;
29
50
const limit = argv . limit ;
30
51
const page = argv . page ;
52
+ const status = argv . status ;
53
+ const trigger = argv . trigger ;
54
+ const pipelineNames = ! _ . isArray ( argv [ 'pipeline-name' ] ) ? [ ( argv [ 'pipeline-name' ] ) ] : argv [ 'pipeline-name' ] ;
55
+ const pipelineIds = ! _ . isArray ( argv [ 'pipeline-id' ] ) ? [ ( argv [ 'pipeline-id' ] ) ] : argv [ 'pipeline-id' ] ;
31
56
32
57
let workflows ;
33
58
// TODO:need to decide for one way for error handeling
34
59
if ( workflowId ) {
35
60
workflows = await workflow . getWorkflowById ( workflowId ) ;
36
61
specifyOutputForSingle ( argv . output , workflows ) ;
37
62
} else {
63
+ if ( _ . isEmpty ( pipelineIds ) && ! _ . isEmpty ( pipelineNames ) ) {
64
+ const pipelines = await pipeline . getAll ( ) ;
65
+ _ . forEach ( pipelineNames , ( pipelineName ) => {
66
+ const matchPipelines = _ . find ( pipelines , pipeline => pipeline . info . name . toString ( ) === pipelineName ) ;
67
+ if ( _ . isArray ( matchPipelines ) ) {
68
+ _ . forEach ( matchPipelines , ( currPipeline ) => {
69
+ pipelineIds . push ( currPipeline . info . id ) ;
70
+ } ) ;
71
+ } else {
72
+ pipelineIds . push ( matchPipelines . info . id ) ;
73
+ }
74
+ } ) ;
75
+ }
38
76
workflows = await workflow . getWorkflows ( {
39
77
limit,
40
78
page,
79
+ status,
80
+ trigger,
81
+ pipelineIds,
41
82
} ) ;
42
83
specifyOutputForArray ( argv . output , workflows ) ;
43
84
}
0 commit comments