Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# go hub binary
FROM golang:alpine AS go
RUN apk --update add ca-certificates git
RUN apk --update add --no-scripts ca-certificates git
RUN go install github.com/github/hub@latest

# python yq binary
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-debian
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# go hub binary
FROM golang:alpine as go
RUN apk --update add ca-certificates git
RUN apk --update add --no-scripts ca-certificates git
RUN go install github.com/github/hub@latest

# python yq binary
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-debian-rootless
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# go hub binary
FROM golang:alpine as go
RUN apk --update add ca-certificates git
RUN apk --update add --no-scripts ca-certificates git
RUN go install github.com/github/hub@latest

# python yq binary
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile-rootless
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# go hub binary
FROM golang:alpine as go
RUN apk --update add ca-certificates git
RUN apk --update add --no-scripts ca-certificates git
RUN go install github.com/github/hub@latest

# python yq binary
Expand Down
2 changes: 1 addition & 1 deletion lib/interface/cli/commands/root/get.cmd.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const get = new Command({
.option('output', {
describe: 'Output format',
alias: 'o',
choices: ['json', 'yaml', 'wide', 'name', 'id'],
choices: ['json', 'yaml', 'wide', 'name', 'id', 'jsonArray', 'yamlArray'],
group: 'Output Options',
})
.option('date-format', {
Expand Down
2 changes: 1 addition & 1 deletion lib/interface/cli/commands/root/get.completion.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function optionHandler({ word, argv, option }) {
return fileDir(word);
}
if (OUTPUT_OPTIONS.includes(option)) {
return ['json', 'yaml', 'wide', 'name', 'id'];
return ['json', 'yaml', 'wide', 'name', 'id', 'jsonArray', 'yamlArray'];
}
return [];
}
Expand Down
2 changes: 2 additions & 0 deletions lib/output/Output.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ const TYPES = {
table: require('./types/table.output'),
id: require('./types/id.output'),
name: require('./types/name.output'),
jsonArray: require('./types/jsonArray.output'),
yamlArray: require('./types/yamlArray.output'),
};

const TABLE_TYPES = ['default', 'wide'];
Expand Down
19 changes: 19 additions & 0 deletions lib/output/types/jsonArray.output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const CFError = require('cf-errors'); // eslint-disable-line
const Entity = require('../../logic/entities/Entity');
const _ = require('lodash');

function output(data) {
const entities = _.isArray(data) ? data : [data];
const jsonArray = [];

_.forEach(entities, (entity) => {
if (!(entity instanceof Entity)) {
throw new CFError('Cannot extract data for "jsonArray" output -- data contains not Entity');
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created this file based on the implementation of json output file. same for yamlArray

}
jsonArray.push(entity.info);
});

return JSON.stringify(jsonArray, null, '\t');
}

module.exports = output;
37 changes: 37 additions & 0 deletions lib/output/types/jsonArray.output.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
const CFError = require('cf-errors');
const Entity = require('../../logic/entities/Entity');
const output = require('./jsonArray.output');

describe('jsonArray output', () => {
it('should return empty array for an empty array', () => {
expect(output([])).toBe('[]');
});

it('should wrap single Entity into array', () => {
const entity = new Entity();
entity.info = { id: '1', status: 'ok' };

const result = JSON.parse(output(entity));
expect(Array.isArray(result)).toBe(true);
expect(result).toHaveLength(1);
expect(result[0]).toEqual(entity.info);
});

it('should keep multiple Entities as array', () => {
const entity1 = new Entity();
entity1.info = { id: '1' };
const entity2 = new Entity();
entity2.info = { id: '2' };

const result = JSON.parse(output([entity1, entity2]));
expect(Array.isArray(result)).toBe(true);
expect(result).toHaveLength(2);
expect(result[0]).toEqual(entity1.info);
expect(result[1]).toEqual(entity2.info);
});

it('should throw CFError if element is not an Entity', () => {
expect(() => output({ id: '1' })).toThrow(CFError);
expect(() => output([new Entity(), {}])).toThrow(CFError);
});
});
20 changes: 20 additions & 0 deletions lib/output/types/yamlArray.output.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const CFError = require('cf-errors');
const Entity = require('../../logic/entities/Entity');
const _ = require('lodash');
const yaml = require('js-yaml');

function output(data) {
const entities = _.isArray(data) ? data : [data];
const yamlArray = [];

_.forEach(entities, (entity) => {
if (!(entity instanceof Entity)) {
throw new CFError('Cannot extract data for "yamlArray" output -- data contains not Entity');
}
yamlArray.push(entity.info);
});

return yaml.dump(yamlArray);
}

module.exports = output;
40 changes: 40 additions & 0 deletions lib/output/types/yamlArray.output.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
const CFError = require('cf-errors');
const yaml = require('js-yaml');
const Entity = require('../../logic/entities/Entity');
const output = require('./yamlArray.output');

describe('yamlArray output', () => {
it('should return empty array for an empty array', () => {
const result = yaml.load(output([]));
expect(Array.isArray(result)).toBe(true);
expect(result).toHaveLength(0);
});

it('should wrap single Entity into array', () => {
const entity = new Entity();
entity.info = { id: '1', status: 'ok' };

const result = yaml.load(output(entity));
expect(Array.isArray(result)).toBe(true);
expect(result).toHaveLength(1);
expect(result[0]).toEqual(entity.info);
});

it('should keep multiple Entities as array', () => {
const entity1 = new Entity();
entity1.info = { id: '1' };
const entity2 = new Entity();
entity2.info = { id: '2' };

const result = yaml.load(output([entity1, entity2]));
expect(Array.isArray(result)).toBe(true);
expect(result).toHaveLength(2);
expect(result[0]).toEqual(entity1.info);
expect(result[1]).toEqual(entity2.info);
});

it('should throw CFError if element is not an Entity', () => {
expect(() => output({ id: '1' })).toThrow(CFError);
expect(() => output([new Entity(), {}])).toThrow(CFError);
});
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "codefresh",
"version": "0.89.5",
"version": "0.89.6",
"description": "Codefresh command line utility",
"main": "index.js",
"preferGlobal": true,
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3558,7 +3558,7 @@ forever-agent@~0.6.1:
resolved "https://registry.yarnpkg.com/forever-agent/-/forever-agent-0.6.1.tgz#fbc71f0c41adeb37f96c577ad1ed42d8fdacca91"
integrity sha512-j0KLYPhm6zeac4lz3oJ3o65qvgQCcPubiyotZrXqEaG4hNagNYO8qdlUrX5vwqv9ohqeT/Z3j6+yW067yWWdUw==

form-data@^2.3.2, form-data@^2.5.4, form-data@~2.3.2:
form-data@^2.3.2, form-data@^2.5.5, form-data@~2.3.2:
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

automatic change which happened when I did yarn install. I can remove it

version "2.5.5"
resolved "https://registry.yarnpkg.com/form-data/-/form-data-2.5.5.tgz#a5f6364ad7e4e67e95b4a07e2d8c6f711c74f624"
integrity sha512-jqdObeR2rxZZbPSGL+3VckHMYtu+f9//KXBsVny6JSX/pa38Fy+bGjuG8eW/H6USNQWhLi8Num++cU2yOCNz4A==
Expand Down