@@ -10,6 +10,19 @@ const Pipeline = require('../../../../logic/entities/Pipeline');
1010
1111const getRoot = require ( '../root/get.cmd' ) ;
1212
13+ /**
14+ * returns a limit based on the passed `--limit, --all` and default values
15+ * The limit for the flag `all` (10k) was set in сli defaults values,
16+ * so as not to touch the pipeline-manager logic (since requests from other places can go to it)
17+ * @param argvLimit {number}- value from `--limit`
18+ * @param allFlag {boolean} - value from `--all`
19+ * @returns {number|* }
20+ * @private
21+ */
22+ function _getLimit ( argvLimit , allFlag ) {
23+ if ( allFlag && _ . isUndefined ( argvLimit ) ) return DEFAULTS . GET_ALL_PIPELINES_LIMIT ;
24+ return argvLimit >= 0 ? argvLimit : DEFAULTS . GET_LIMIT_RESULTS ;
25+ }
1326
1427const command = new Command ( {
1528 command : 'pipelines [id..]' ,
@@ -44,34 +57,39 @@ const command = new Command({
4457 default : [ ] ,
4558 } )
4659 . option ( 'limit' , {
47- describe : 'Limit amount of returned results' ,
48- default : DEFAULTS . GET_LIMIT_RESULTS ,
60+ describe : `Limit amount of returned results [default: ${ DEFAULTS . GET_LIMIT_RESULTS } ]` ,
61+ } )
62+ . option ( 'all' , {
63+ describe : 'Remove default limit of returned result' ,
4964 } )
5065 . option ( 'page' , {
5166 describe : 'Paginated page' ,
5267 default : DEFAULTS . GET_PAGINATED_PAGE ,
5368 } ) ;
5469 } ,
5570 handler : async ( argv ) => {
56- const { id : ids , name, d : decryptVariables , projectId, project : projectName } = argv ;
57- const limit = argv . limit ;
58- const offset = ( argv . page - 1 ) * limit ;
71+ const { id : ids , name, d : decryptVariables , projectId, project : projectName , all } = argv ;
72+ const limit = _getLimit ( argv . limit , all ) ;
73+ const offset = ( argv . page - 1 ) * ( limit || 0 ) ;
5974 const labels = prepareKeyValueFromCLIEnvOption ( argv . label ) ;
60-
6175 debug ( `decrypt: ${ decryptVariables } ` ) ;
6276 if ( ! _ . isEmpty ( ids ) ) {
6377 const pipelines = [ ] ;
6478 for ( const id of ids ) {
6579 try {
66- const currPipeline = await sdk . pipelines . get ( { name : id , decryptVariables } ) ;
80+ const currPipeline = await sdk . pipelines . get ( {
81+ name : id ,
82+ decryptVariables,
83+ } ) ;
6784 pipelines . push ( Pipeline . fromResponse ( currPipeline ) ) ;
6885 } catch ( err ) {
6986 if ( pipelines . length ) {
7087 Output . print ( pipelines ) ;
7188 }
7289
7390 debug ( err . toString ( ) ) ;
74- const message = err . toString ( ) . includes ( 'not find' ) ? `Pipeline '${ id } ' was not found.` : 'Error occurred' ;
91+ const message = err . toString ( )
92+ . includes ( 'not find' ) ? `Pipeline '${ id } ' was not found.` : 'Error occurred' ;
7593 throw new CFError ( {
7694 cause : err ,
7795 message,
@@ -89,6 +107,7 @@ const command = new Command({
89107 } ) ) ) ;
90108 _projectId = project . id ;
91109 }
110+
92111 const pipelines = await sdk . pipelines . list ( {
93112 limit,
94113 offset,
@@ -102,4 +121,5 @@ const command = new Command({
102121} ) ;
103122
104123module . exports = command ;
124+ module . exports . _getLimit = _getLimit ;
105125
0 commit comments