1- const debug = require ( 'debug' ) ( 'codefresh:cli:create:context ' ) ;
1+ const debug = require ( 'debug' ) ( 'codefresh:cli:create:pipelines2 ' ) ;
22const Command = require ( '../../Command' ) ;
33const CFError = require ( 'cf-errors' ) ;
44const _ = require ( 'lodash' ) ;
5- const { pipeline } = require ( '../../../../logic' ) . api ;
6- const { specifyOutputForSingle, specifyOutputForArray } = require ( '../../helpers/get' ) ;
7- const getRoot = require ( '../root/get.cmd' ) ;
85const DEFAULTS = require ( '../../defaults' ) ;
6+ const { pipeline } = require ( '../../../../logic' ) . api ;
7+ const { prepareKeyValueFromCLIEnvOption, printError } = require ( '../../helpers/general' ) ;
8+ const { specifyOutputForArray } = require ( '../../helpers/get' ) ;
99
10+ const getRoot = require ( '../root/get.cmd' ) ;
1011
1112
1213const command = new Command ( {
1314 command : 'pipelines [id..]' ,
1415 aliases : [ 'pip' , 'pipeline' ] ,
1516 parent : getRoot ,
1617 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' ,
1818 webDocs : {
1919 category : 'Pipelines' ,
2020 title : 'Get Pipeline' ,
2121 } ,
2222 builder : ( yargs ) => {
2323 return yargs
2424 . positional ( 'id' , {
25- describe : 'Pipeline id' ,
25+ describe : 'Pipeline name/ id' ,
2626 } )
27- . option ( 'repo-owner' , {
28- describe : 'Repository owner' ,
27+ . option ( 'decrypt-variables' , {
28+ alias : 'd' ,
29+ describe : 'Will decrypt encrypted variables' ,
2930 } )
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 : [ ] ,
3238 } )
3339 . option ( 'limit' , {
3440 describe : 'Limit amount of returned results' ,
@@ -37,40 +43,43 @@ const command = new Command({
3743 . option ( 'page' , {
3844 describe : 'Paginated page' ,
3945 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+ } ) ;
4947 } ,
5048 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 ;
5550 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+ }
5765
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+ }
6373 }
74+ specifyOutputForArray ( output , pipelines ) ;
6475 } else {
65- pipelines = await pipeline . getAll ( {
66- repoOwner,
67- repoName,
68- name,
76+ specifyOutputForArray ( output , await pipeline . getAll ( {
6977 limit,
70- page,
71- } ) ;
78+ offset,
79+ name,
80+ labels,
81+ } ) ) ;
7282 }
73- specifyOutputForArray ( argv . output , pipelines ) ;
7483 } ,
7584} ) ;
7685
0 commit comments