Skip to content

Commit 3948c28

Browse files
olegz-codefreshpasha-codefresh
authored andcommitted
added flag --all for getting pipelines without limit (#370)
* [other] - added flag `--all` for getting pipelines without limit (in such cases, actually limit of 10k) * [other] - chamged >-1 to >=0 * [other] - v up * bump version
1 parent 39bffd7 commit 3948c28

File tree

5 files changed

+49
-12
lines changed

5 files changed

+49
-12
lines changed

lib/interface/cli/commad-line-interface.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,7 @@ async function startCommandLine() {
4949
}
5050
}
5151
});
52-
_.forEach(rootCommands, (command) => {
53-
yargs.command(command.toCommand());
54-
});
52+
_.forEach(rootCommands, command => yargs.command(command.toCommand()));
5553

5654
return yargs // eslint-disable-line
5755
.env('CF_ARG_') // this means that every process.env.CF_ARG_* will be passed to argv

lib/interface/cli/commands/pipeline/get.cmd.js

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,19 @@ const Pipeline = require('../../../../logic/entities/Pipeline');
1010

1111
const 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

1427
const 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

104123
module.exports = command;
124+
module.exports._getLimit = _getLimit;
105125

lib/interface/cli/commands/pipeline/pipeline.sdk.spec.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
const DEFAULTS = require('../../defaults');
12
const getCmd = require('./get.cmd').toCommand();
23
const deleteCmd = require('./delete.cmd').toCommand();
34
const BasePipeline = require('./run.base');
@@ -32,6 +33,7 @@ describe('pipeline', () => {
3233

3334
describe('commands', () => {
3435
describe('get', () => {
36+
const { _getLimit } = require('./get.cmd');
3537
it('should handle getting given id', async () => {
3638
const argv = { id: ['some id'] };
3739
await getCmd.handler(argv);
@@ -45,6 +47,22 @@ describe('pipeline', () => {
4547
await getCmd.handler(argv);
4648
await verifyResponsesReturned([response]); // eslint-disable-line
4749
});
50+
51+
it('should return limit from arg', async () => {
52+
expect(_getLimit(10, true)).toEqual(10);
53+
});
54+
55+
it('should return zero limit', async () => {
56+
expect(_getLimit(0, true)).toEqual(0);
57+
});
58+
59+
it('should return default limit', async () => {
60+
expect(_getLimit(undefined,false)).toEqual(DEFAULTS.GET_LIMIT_RESULTS);
61+
});
62+
63+
it('should return `unlimited` value', async () => {
64+
expect(_getLimit(undefined,true)).toEqual(DEFAULTS.GET_ALL_PIPELINES_LIMIT);
65+
});
4866
});
4967

5068
// decided to follow unit tests modularity concept

lib/interface/cli/defaults.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const DEFAULTS = {
66
CFCONFIG: `${process.env.HOME || process.env.USERPROFILE}/.cfconfig`,
77
DEBUG_PATTERN: 'codefresh',
88
GET_LIMIT_RESULTS: 25,
9+
GET_ALL_PIPELINES_LIMIT: 10000,
910
GET_PAGINATED_PAGE: 1,
1011
CODEFRESH_REGISTRIES: ['r.cfcr.io', '192.168.99.100:5000'],
1112
WATCH_INTERVAL_MS: 3000,

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codefresh",
3-
"version": "0.37.0",
3+
"version": "0.37.2",
44
"description": "Codefresh command line utility",
55
"main": "index.js",
66
"preferGlobal": true,

0 commit comments

Comments
 (0)