@@ -10,6 +10,19 @@ const Pipeline = require('../../../../logic/entities/Pipeline');
10
10
11
11
const getRoot = require ( '../root/get.cmd' ) ;
12
12
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
+ }
13
26
14
27
const command = new Command ( {
15
28
command : 'pipelines [id..]' ,
@@ -44,34 +57,39 @@ const command = new Command({
44
57
default : [ ] ,
45
58
} )
46
59
. 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' ,
49
64
} )
50
65
. option ( 'page' , {
51
66
describe : 'Paginated page' ,
52
67
default : DEFAULTS . GET_PAGINATED_PAGE ,
53
68
} ) ;
54
69
} ,
55
70
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 ) ;
59
74
const labels = prepareKeyValueFromCLIEnvOption ( argv . label ) ;
60
-
61
75
debug ( `decrypt: ${ decryptVariables } ` ) ;
62
76
if ( ! _ . isEmpty ( ids ) ) {
63
77
const pipelines = [ ] ;
64
78
for ( const id of ids ) {
65
79
try {
66
- const currPipeline = await sdk . pipelines . get ( { name : id , decryptVariables } ) ;
80
+ const currPipeline = await sdk . pipelines . get ( {
81
+ name : id ,
82
+ decryptVariables,
83
+ } ) ;
67
84
pipelines . push ( Pipeline . fromResponse ( currPipeline ) ) ;
68
85
} catch ( err ) {
69
86
if ( pipelines . length ) {
70
87
Output . print ( pipelines ) ;
71
88
}
72
89
73
90
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' ;
75
93
throw new CFError ( {
76
94
cause : err ,
77
95
message,
@@ -89,6 +107,7 @@ const command = new Command({
89
107
} ) ) ) ;
90
108
_projectId = project . id ;
91
109
}
110
+
92
111
const pipelines = await sdk . pipelines . list ( {
93
112
limit,
94
113
offset,
@@ -102,4 +121,5 @@ const command = new Command({
102
121
} ) ;
103
122
104
123
module . exports = command ;
124
+ module . exports . _getLimit = _getLimit ;
105
125
0 commit comments