diff --git a/lib/interface/cli/commands/workflow/get.cmd.js b/lib/interface/cli/commands/workflow/get.cmd.js index b20b2591a..3725448ca 100644 --- a/lib/interface/cli/commands/workflow/get.cmd.js +++ b/lib/interface/cli/commands/workflow/get.cmd.js @@ -114,8 +114,8 @@ const command = new Command({ from, to, } = argv; - const pipelineNames = !_.isArray(argv['pipeline-name']) ? [(argv['pipeline-name'])] : argv['pipeline-name']; - const pipelineIds = !_.isArray(argv['pipeline-id']) ? [(argv['pipeline-id'])] : argv['pipeline-id']; + const pipelineNames = _.compact(!_.isArray(argv['pipeline-name']) ? [(argv['pipeline-name'])] : argv['pipeline-name']); + const pipelineIds = _.compact(!_.isArray(argv['pipeline-id']) ? [(argv['pipeline-id'])] : argv['pipeline-id']); const requestOptions = { limit, @@ -140,14 +140,14 @@ const command = new Command({ const pipelines = await sdk.pipelines.list({ id: pipelineNames, }); - if (!_.isEmpty(pipelines)) { - _.forEach(pipelines.docs, (currPipeline) => { - pipelineIds.push(currPipeline.metadata.id); - }); - requestOptions.pipeline = pipelineIds; - } else if (_.isEmpty(pipelineIds)) { + const pipelineDocs = _.get(pipelines, 'docs'); + if (_.isEmpty(pipelineDocs)) { throw new CFError('Cannot find any builds with these pipelines names'); } + _.forEach(pipelineDocs, (currPipeline) => { + pipelineIds.push(currPipeline.metadata.id); + }); + requestOptions.pipeline = pipelineIds; } else if (!_.isEmpty(pipelineIds)) { requestOptions.pipeline = pipelineIds; } diff --git a/lib/interface/cli/commands/workflow/workflow.sdk.spec.js b/lib/interface/cli/commands/workflow/workflow.sdk.spec.js index abf73ec87..e9d2e328c 100644 --- a/lib/interface/cli/commands/workflow/workflow.sdk.spec.js +++ b/lib/interface/cli/commands/workflow/workflow.sdk.spec.js @@ -61,6 +61,12 @@ describe('workflow commands', () => { await verifyResponsesReturned(responses); // eslint-disable-line }); + it('should throw when pipeline name does not match any pipeline', async () => { + const argv = { 'pipeline-name': 'does-not-exist' }; + request.__setResponse({ statusCode: 200, body: { docs: [] } }); + await expect(getCmd.handler(argv)).rejects.toThrow('Cannot find any builds with these pipelines names'); + }); + it('should handle getting all', async () => { const argv = { 'pipeline-name': [] }; const response = {